Closed adm271828 closed 6 years ago
Thanks for finding that bug and documentation issue. Both have been fixed in 8dd40fab4fbd1a639bcfec34c346dc234d637d9a and afa73c5be3475b8af4cf17084efe0b27a5f4f6d8.
As for the feature request to allow for fields to be excluded from dict serialization, let me ponder that, and I will get back to you.
I see at least 2 use cases:
to_dict()
as a serializer whose result will be sent in response to a REST query. In which case, a control over fieds that are not exposed might be neededI'll go ahead and have this feature added. I might not be able to get to until the weekend so if you wanted to take a stab at a PR, that'd be fine by me. Otherwise, I'll try to get it done soon.
I've implemented the None
adapter support to exclude fields from dict serialization in 97f80f526449839f488663d29ebe04d4220c3dd3 and released in v1.1.3
: https://pypi.org/project/sqlservice/1.1.3/
Thanks again for the feature idea and bug report!
Hello Derrick,
I suggest the last test in
_get_dict_adapter
to be replaced with:This will avoid an exception when
__args_dict__
does not provide an adapter for every key, and allow the default adapter to be returned.The following works because
email
isNone
:Otherwise, when serializing
email
, the test ends up withcls
being a string ('name'
) and not a type:Moreover the documentation says the adapter can be a function that accepts up to three arguments. It seems to me this only work if it accepts exactly three argument (otherwise raise a TypeError and complains it was given 3 arguments).
And wouldn't it be a nice feature to prevent a given field's serialization if the adapter in
__dict_args__
isNone
? For instance:BTW very nice package. I came to it when trying to reuse a model that was developped inside a Flask application...
Best regards,
Antoine