Repository navigation
fix(mediarequest): refactor to .save() instead of .update() for TypeORM - #1619
Closed
gauthier-th wants to merge 4 commits into
Closed
gauthier-th wants to merge 4 commits into
gauthier-th wants to merge 4 commits into
Conversation
The .update() method of TypeORM doesn't come with all the functionalities of the .save() method. Its goal is to partially update a Repository without doing any extra operation. This introduces issues with event from the database subscriber not triggered correctly, because of this partial update: typeorm/typeorm#2809 (comment) This PR rollback to .save() instead of .update() to avoid the aforementioned issues, at the cost of some lifehook issues. These issues are happening with PostgreSQL because the .save() method shouldn't be used inside an Entity Listener, an Event Subscriber should be used instead: https://orkhan.gitbook.io/typeorm/docs/listeners-and-subscribers#what-is-an-entity-listener
Member
|
Just to add to the description: the lifecycle issues also affect sqlite to an extent in some scenarios due to database access in event listeners (which is as mentioned, not supported) |
1 task done
…emove Replace `getRepository(Media)` calls with `event.manager` in the `afterRemove` hook so that parent-media status resets run within the same transaction/QueryRunner (important for postgresql. Doesnt affect sqlite).
…t hook recursion Restrict cascade options on the MediaRequest→Media relation to only `insert` and `remove`to avoid nested subscriber/AfterUpdate recursion when saving entities.
fallenbagel
force-pushed
the
fix-typeorm-update
branch
from
May 1, 2025 14:48
f823e6a to
cd8d574
Compare
3 tasks
Contributor
|
Tested cause I was having the same problem as reported in the issue and now it's fixed thanks ! |
1 task done
|
This pull request has merge conflicts. Please resolve the conflicts so the PR can be successfully reviewed and merged. |
Member
|
Superseded by #1631 |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The .update() method of TypeORM doesn't come with all the functionalities of the .save() method. Its goal is to partially update a Repository without doing any extra operation. This introduces issues with event from the database subscriber not triggered correctly, because of this partial update: typeorm/typeorm#2809 (comment)
A positive side effect of this change is that web push are now fixed.
This PR rollback to .save() instead of .update() to avoid the aforementioned issues,
at the cost of some lifehook issues. These issues are happening with PostgreSQL because the .save() method shouldn't be used inside an Entity Listener, an Event Subscriber should be used instead: https://orkhan.gitbook.io/typeorm/docs/listeners-and-subscribers#what-is-an-entity-listenerEDIT (By @fallenbagel):
This PR consolidates all database‐accessing lifecycle hooks into the MediaRequestSubscriber as this is the recommended way of doing database calls.
See: https://orkhan.gitbook.io/typeorm/docs/listeners-and-subscribers#what-is-an-entity-listener.
It also tightens the cascade options on the
MediaRequest→Mediarelation to onlyinsertandremoveto avoidhook‐within‐hookrecursions that could cause unexpected behavior.These changes should guard against recursive hook invocations in any database backend and simplify the entity lifecycle.
Upstream PR also opened: sct/overseerr#4124
Screenshot (if UI-related)
To-Dos
pnpm buildpnpm i18n:extract