default
value for field gets deepcopied causing sentinels to get copied
#9328
Unanswered
txomon
asked this question in
Question & Answer
Replies: 1 comment
-
I believe you can make use of |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have found that the use of sentinel values such as
object()
fails with the current implementation of serializers.My usecase is when I want to distinguish between the user not providing a value and not providing the attribute at all. Example:
Any object deserialized by
MySerializer
, whenevermy_field
is not sent, will result in a randomobject()
being generated, and thereforeis
comparison not being able to be used.I have narrowed it down to all the generator based
_*_fields()
properties that usecopy.deepcopy()
under the hood, and generate new instances for every deserialization.It seems like a way to overcome this is through setting
default=lambda: NO_ATTR
, but that doesn't seem like a nice solution. I'm not sure on whether this is a well known limitation to developers, but I haven't been able to find any references. Would it make sense to at least document this limitation?Checklist
Beta Was this translation helpful? Give feedback.
All reactions