-
-
Notifications
You must be signed in to change notification settings - Fork 630
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
Field: respect single responsability principle, don't access parent object #1046
Comments
I've been giving this a bit of thought.
It wasn't clear to me straight away, just an intuition, but the question is about the responsibility of the field. Hence my link to #799.
I agree with this. It conflicts with aforementioned fields and with #900/#940. We could drop these fields and state that those use case should be covered by other means. Those means can be properties in the model, but some may argue this is the responsibility of the serialization layer. Or it can be done in pre/post_dump/load decorators, but if we want to rely on them for this, we'll probably want to enforce the order of the decorators (#600). We could postpone this and #799 to marshmallow 4.x. |
Remove
|
I have the feeling we could simplify
Field._serialize
signature from_serialize(self, value, attr, obj, **kwargs)
to_serialize(self, value)
.From a quick search,
obj
is used inNested
to populate theValidationError
. I need to get my head around this. Shouldn't it benested_obj
?It is also used in
FormattedString
. This field achieves a function that could be achieved otherwise (property, pre_dump,...). I think it could be dropped without too much collateral damage.There may be an issue with
Function
, too.I didn't see where
attr
andkwargs
are used.It boils down to whether a field should have access to the whole structure or only its own value.
This is more or less related to #799 and probably #900/#940.
Edit: Marking as 3.0 because it is a breaking change, but it could be postponed, just like #799. If my intuition is correct, it could make for a simpler and saner interface, forbidding hard-to-debug corner cases.
The text was updated successfully, but these errors were encountered: