New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: subscriber afterXY functions should be called after the transaction is commited #743
Comments
no. What queries are you executing in your subscribers? You must use entity manager provided by subscribers to execute all queries you do there |
If you still have issues or want to discuss something - let me know. |
I think I have same issue as mentioned above. Imagine following use-case: I have an app where users can be awarded a badge. When they recieve I want to send a push-notification to them. Proposed solutions:
I hope it's understandable. |
all "after" events are called after all queries are executed in terms of a single |
Found a workaround for this. You can commit the transaction you are currently in but you then have to immediately open a new transaction. Typeorm will then close an empty transaction I think. You can try it like this: event.queryRunner.commitTransaction(); // Commit transaction, to make it available in DB |
@pleerock Hi! Is there any specific reason for emitting events before the transaction has actually been successfully committed? Would a PR allowing a new type of event (or the same event but with an additional flag) "once commit is done" be acceptable? Thanks! EDIT - Ok this has been discussed here and here. I get the "use case", where Events are somewhat extensions to the transaction/query and need to make it fail if they fail. I'd still like to know if a PR would be somewhat acceptable (to only trigger some code execution if the transaction has been committed). |
news on this? same problem. |
Description: After trying to update to the latest release we have experienced failing queries which just worked fine before.
Observed behaviour: The reason for this seems to be that TypeORM will wait until the
afterXY
subscriber calls finish before committing the transaction. (This works fine when no other query has been made in the subscriber, but it causes the transaction to fail and rollback when the subscriber try to execute queries.Expected behaviour: TypeORM should
COMMIT
the transaction before calling the subscriber'safterXY
functions.The text was updated successfully, but these errors were encountered: