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

"atomic"-ness of hooks should be configureable or removed #97

Closed
amcclosky opened this issue Jan 30, 2022 · 6 comments
Closed

"atomic"-ness of hooks should be configureable or removed #97

amcclosky opened this issue Jan 30, 2022 · 6 comments

Comments

@amcclosky
Copy link
Contributor

amcclosky commented Jan 30, 2022

First of all, thanks for this library. The API is really well done.

However, today I discovered that in #85 the change was made to force hooks to run inside of a transaction, which for many cases is desirable behavior, however one of my uses for lifecycle hooks is to queue background jobs in AFTER_SAVE assuming any calls to the model's save() will either observe the default django orm autocommit behavior or abide by whatever the behavior set by its current context will be.

Forcing a transaction / savepoint that wraps all model hooks using the atomic decorator means you can't safely make a call to an external service(or queue a celery / rq job) and assume the model changes will be visible. For example, it is not unusual for a background job to begin execution before the transaction that queued the job commits.

I'd be happy to open a PR that either reverts #85 or makes the current behavior configureable in some way depending no your preference if you are open to it.

@rsinger86
Copy link
Owner

rsinger86 commented Jan 30, 2022 via email

@amcclosky
Copy link
Contributor Author

amcclosky commented Jan 30, 2022

I'm looking at it right now.

Making it globally configureable looks straightforward which is probably what I will open a PR for.

The "better" solution I may experiment with later would be to add a new set of hooks, POST_*, that complements the existing AFTER_* hooks which execute only after a transaction succeeds.

@rsinger86
Copy link
Owner

rsinger86 commented Jan 30, 2022 via email

@rsinger86
Copy link
Owner

rsinger86 commented Jan 30, 2022 via email

@amcclosky
Copy link
Contributor Author

I had similar thoughts on the decorator arg. That would be cleaner IMO. I'll see what I can come up with. This is my first time back in Django orm-land in awhile so I am reacquainting myself with how the internals work these days.

@reedjones
Copy link

Does this mean that django 4.x support is working now?

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

3 participants