Multiple attribute fields for the class attribute
See original GitHub issueLike it shown in the example:
class UserSchema(Schema):
name = fields.String()
email_addr = fields.String(attribute="email")
date_created = fields.DateTime(attribute="created_at")
user = User('Keith', email='keith@stones.com')
ser = UserSchema()
result = ser.dump(user)
pprint(result)
# {'name': 'Keith',
# 'email_addr': 'keith@stones.com',
# 'date_created': '2014-08-17T14:58:57.600623+00:00'}
It would be great to be able to specify multiple attributes like it done in golang tags. https://stackoverflow.com/questions/18635671/how-to-define-multiple-name-tags-in-a-struct
something like this:
class UserSchema(Schema):
name = fields.String()
email_addr = fields.String(attributes=("email", "e-mail"))
date_created = fields.DateTime(attribute="created_at")
user = User('Keith', email='keith@stones.com')
ser = UserSchema()
result = ser.dump(user)
pprint(result)
# {'name': 'Keith',
# 'email_addr': 'keith@stones.com',
# 'date_created': '2014-08-17T14:58:57.600623+00:00'}
user = User('Keith', e-mail='keith@stones.com')
ser = UserSchema()
result = ser.dump(user)
pprint(result)
# {'name': 'Keith',
# 'email_addr': 'keith@stones.com',
# 'date_created': '2014-08-17T14:58:57.600623+00:00'}
Marshmallow already extensively used in testing, but this addition will open a new horizon for testing (especially in comparators related area)
If it sounds reasonable I could dig into it.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How To: Add the same field to multiple feature classes ...
The instructions provided describe how to add the same field to multiple feature classes simultaneously.
Read more >Update Multiple Fields with a Single Attribute Rule - YouTube
Learn about a new capability with ArcGIS Pro 2.7 and Enterprise 10.9 that enables you to update multiple fields with a single attribute...
Read more >Applying the same attribute values to multiple features in a layer
Applying the same attribute values to multiple features in a layer · Click the Edit tool · Click the Attributes button · Click...
Read more >Can you apply a attribute to multiple fields in C#? - Stack ...
Is it possible in C# to apply a single attribute to multiple fields at once? public class MyClass { [SomeAttribute] public int m_nVar1;...
Read more >HTML multiple Attribute - W3Schools
The multiple attribute is a boolean attribute. When present, it specifies that the user is allowed to enter/select more than one value.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK, but what would be the logic from the
Field
point of view? Pick the first attribute of the list that holds a value?The feature you’re asking for would have an undefined behaviour when dumping if both attributes are in the object.
You should use different schemas for this use case.
In testing, you usually have to map the data from different sources like databases/API. This proposal is like some kind of such mapper.
Actually, we can just throw a custom exception.
I’ve got your point if it will break marshmallow ideology let’s just close this issue.