Skip to content
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

Using Entity.flush does not alert EntityHook subscribers #1225

Closed
KennethWussmann opened this issue May 5, 2021 · 1 comment
Closed

Using Entity.flush does not alert EntityHook subscribers #1225

KennethWussmann opened this issue May 5, 2021 · 1 comment

Comments

@KennethWussmann
Copy link

Hey,

I'm using EntityHooks to maintain an updatedAt column on my entities and need the updatedAt value during the same transaction where the entity was updated. As the EntityHooks are only called on commit, I added a Entity.flush() call to force Exposed to flush the outstanding update & so the updatedAt hook to take effect.

Expected behaviour
Looking at the code of the flush() function it adds an update event to the queue. I expected calling flush() with outstanding updates will also notify EntityHook subscribers.

I added a test repo here to showcase the expected behaviour: https://github.com/KennethWussmann/exposed-entity-flush-hook-bug/blob/main/src/test/kotlin/exposedissue/EntityHookTest.kt#L18-L59

Actual behaviour
Calling flush() doesn't notify EntityHook subscribers, even though it commits UPDATE statements to the database.

I also added a test to show how it currently looks like: https://github.com/KennethWussmann/exposed-entity-flush-hook-bug/blob/main/src/test/kotlin/exposedissue/EntityHookTest.kt#L61-L103

Version used: 0.31.1

Thank you!

@Tapac
Copy link
Contributor

Tapac commented May 11, 2021

Fixed in master. Events will be fired just after the entity created/updated/deleted not before the transaction commit.

@Tapac Tapac closed this as completed May 11, 2021
SchweinchenFuntik pushed a commit to SchweinchenFuntik/Exposed that referenced this issue Oct 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants