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

ID is None in model observer message when model objects are deleted with atomic transactions #207

Open
dkmorgan opened this issue Nov 7, 2024 · 2 comments

Comments

@dkmorgan
Copy link

dkmorgan commented Nov 7, 2024

I have a ModelViewSet with a custom destroy() definition decorated with @transaction.atomic.
When the model object is deleted, the message passed into the model_observer handler does not contain the ID.

I have checked that the ID is present in the instance when ModelObserver.post_delete_receiver() is called.
However, the ID has changed to None when ModelObserver.post_change_receiver() is called.

The ID does not change to None if I remove the @transaction.atomic decorator from destroy() in the ModelViewSet.

Is this behavior expected?
If so, are there any workarounds to retain the ID when model objects are deleted via atomic transactions?
I would like to avoid defining post_delete signal handlers for all my models to send the delete notifications via the AsyncAPIConsumer containing the model_observer definition.

@hishnash
Copy link
Member

Soory I did not spot this sooner.

This is interesting, are other fields still populated (is it just the ID that is lost?)

@dkmorgan
Copy link
Author

dkmorgan commented Nov 24, 2024

This is interesting, are other fields still populated (is it just the ID that is lost?)

Yes.
My guess is that the delete transaction has completed and the ID is set to None in the referenced instance after ModelObserver.post_change_receiver() is called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants