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

Examples for post_save signal usage #248

Closed
arski opened this issue Dec 7, 2016 · 6 comments
Closed

Examples for post_save signal usage #248

arski opened this issue Dec 7, 2016 · 6 comments

Comments

@arski
Copy link

arski commented Dec 7, 2016

Hi, could you please elaborate/add specific examples how FieldTracker will and will NOT work with post_save signal handlers. Im referring to this in the docs:

Due to the implementation of FieldTracker, post_save signal handlers relying on field tracker methods should only be registered after model creation.

Thanks!

@romgar
Copy link
Collaborator

romgar commented Dec 8, 2016

@carljm you had some use cases in mind when writing this?

@carljm
Copy link
Collaborator

carljm commented Dec 10, 2016

I think @treyhunner (author of FieldTracker) might have better memory. IIRC it's just that FieldTracker itself relies on a post_save signal handler, and signal handlers run in the order they are registered, so if you have a post_save handler that needs to use FieldTracker data from that save, it needs to be registered later. Normally this isn't a problem if you register your listener in the normal way, outside of model class creation (that is, at module level or in an AppConfig.ready method); it's only a potential problem if you register the handler in e.g. a field contribute_to_class method, or something else that occurs during model class creation.

@arski
Copy link
Author

arski commented Dec 11, 2016

@carljm you mean FieldTracker clears it's "changed" states in a post_save handler, so basically your handler must get there before that happens? Sounds a bit flaky to be used reliably.

I tested with a post_save handler in my handlers.py file and it doesn't seem to be passed anything to instance.tracker.changed() e.g., so I guess that is too late already :(

@carljm
Copy link
Collaborator

carljm commented Dec 11, 2016

@arski No, that's the opposite of what I described.

But it looks like I was wrong anyway, FieldTracker doesn't use post_save at all, it patches the model save method. I've never really used FieldTracker and don't recall what that doc sentence is about (nor do I know why your test with post_save isn't working, it should work AFAIK); hopefully @treyhunner can clarify.

@kezabelle
Copy link
Collaborator

I believe that the documentation line being discussed was added by Trey after we briefly did change to using a signal, which we subsequently reverted. The root issue was #83 (pickling), #130 (PR) fixed that, but #143 meant it got reverted.

@carljm
Copy link
Collaborator

carljm commented Dec 12, 2016

Thanks @kezabelle. I guess maybe that sentence should just be removed then.

@Mogost Mogost closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2023
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

5 participants