-
-
Notifications
You must be signed in to change notification settings - Fork 628
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
Add field-level pre/post-load API #2787
Comments
Why is this considered a breaking change? |
sorry for the confusion. The breaking change refers to the 'validators transform values' alternative, not the proposed approach |
on second thought, i don't think field-level pre/post-dump makes as much sense as pre/post-load. field-level transformations are much less common on serialization than in deserialization, and custom fields already address the rare cases when they're necessary. |
I also have medium confidence that |
proof of concept of the pre_load and post_load parameters in #2799 |
field level pre/post load transformers are more convenient than schema-level ones for some tasks, as shown by your tests in #2799. It allows one-liners such as age = fields.Float(post_load=[multiply_by_2, decrement]) I see 3 cases:
#1391 could be addressed by creating a base schema that trims whitespaces in pre-load. |
@lafrech i agree that field-level |
Oh, I thought you were talking about the whole feature. Yes, I agree. The benefit of the decorator would be to present the same multiple-fields interface as Note that if processors can only be passed as parameters, the order is obvious, while if we allow decorators, questions may arise about how to enforce an order (just like with schema-level processors #600). |
exactly. i've updated the OP to remove the decorator API from consideration |
As suggested by @lafrech in #2786 (review), we can enable pre/post-load on fields to address use cases like whitespace trimming (#1391) via an API similar to the schema-level pre/post_load/dump API.
Something like:
@pre/post_load
Alternatives considered
Allow validators to transform values
Decorator API
update: this was considered as part of the original proposal but rejected/tabled (#2787 (comment) and #2787 (comment))
The text was updated successfully, but these errors were encountered: