-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Clarify behavior of attribute
for load-only fields
#2145
Comments
You're right about the documentation issue. I think this was discussed a while back and I'm surprised it wasn't fixed already. I'm afraid you're out of luck here because you'd need to set Your use case is a corner case that might not be worth removing that protection. It can be achieved by using two schemas, obviously. I don't see any other mean. |
Oh, right. That's because we only check data_keys for fields that are not load-only. The rationale is that one may want to load the same data with multiple fields, while it would be wrong to dump multiple attributes to the same key. Well, good for you. I'm labeling this a doc issue, then. |
I just pushed a commit in :param data_key: The name of the dict key in the external representation, i.e.
the input of `load` and the output of `dump`.
If `None`, the key will match the name of the field.
:param attribute: The name of the key/attribute in the internal representation, i.e.
the output of `load` and the input of `dump`.
If `None`, the key/attribute will match the name of the field.
Note: This should only be used for very specific use cases such as
outputting multiple fields for a single attribute, or using keys/attributes
that are invalid variable names, unsuitable for field names. In most cases,
you should use ``data_key`` instead. Closing. Please comment if you think t is still ambiguous. |
In the docs, it says that:
However, it also affects the deserialization part:
https://github.com/marshmallow-code/marshmallow/blob/dev/src/marshmallow/schema.py#L681
e.g.
I've used
data_key
with different names to show distinction betweenattribute
anddata_key
usage. My use case is:{"some_field: "http://test"}
as the result ofSchema.dump(SomeThing(some_field_url="http://test"))
{"some_field": <BytesIO>}
as the result ofSchema.load({"some_field": "base64 representation of something"})
.The text was updated successfully, but these errors were encountered: