You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#992 prevents two fields from using the same attribute. The intent was prevent user error.
However, there might be a legitimate use case where a user might want to serialize an attribute in two different ways. This was brought to my attention in marshmallow-code/marshmallow-sqlalchemy#121 .
To illustrate: say I have SchoolSchema which serializes both student_ids and nested representations of students.
frommarshmallowimportSchema, fieldsclassStudentSchema(Schema):
id=fields.Int()
classSchoolSchema(Schema):
student_ids=fields.Pluck(
StudentSchema,
'id',
many=True,
attribute='students',
)
students=fields.List(fields.Nested(StudentSchema))
schema=SchoolSchema()
# ValueError: The attribute argument for one or more fields collides with another field's name or attribute argument. Check the following field names and attribute arguments: ['students']
Yeah, and I still think it's an acceptable compromise. I just hadn't seen anyone try to do the above until I saw marshmallow-code/marshmallow-sqlalchemy#121 , which made me think it could be a legit use case.
#992 prevents two fields from using the same
attribute
. The intent was prevent user error.However, there might be a legitimate use case where a user might want to serialize an attribute in two different ways. This was brought to my attention in marshmallow-code/marshmallow-sqlalchemy#121 .
To illustrate: say I have SchoolSchema which serializes both student_ids and nested representations of students.
Is this a use case we want to support?
cc @lafrech
The text was updated successfully, but these errors were encountered: