Addition of pre_save_validation and move of pre_save to after validation. #345
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Howdy!
My use case is thus: I want to use
pre_save
to hook automatic slug creation in a dynamic way. E.g.:The internals of the
slugify
decorator register apre_save
handler with the class being decorated. Unfortunately, this hook needs to know if the record is being created (even forced as an insert) in order to properly generate the slug. (Mutable identifies if on subsequent non-insert saves the slug should be updated if the source has changed; usually no.) The use ofpost_save
would be bad, requiring additional database round-trips.This pull request moves
pre_save
to below the validation and determination of creation state and adds a new decoratorpre_save_validation
wherepre_save
once was. If hooks were written according to the docs (with the encompassing**kwargs
declaration) then this change won't cause errors, but the behaviour is slightly different. If the old behaviour is desired existingpre_save
hooks will need to switch topre_save_validation
.