-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Resetting a CharFiled to an empty string after fix for #3130 #3318
Comments
I'm sorry it's a bit abstract to me. Do you have a failing test case or snippet we could look at ? |
Hi Xavier, thanks for your prompt reply. You can reproduce the problem with the tutorial. The
(btw I wonder why the To reproduce the problem:
Adding
to the I forget to mention that the problem occurs with HTML requests only, not with JSON requests (as can also be reproduced in the browsable API). The reason for the described behaviour is that with the change introduced in commit d231f36 the empty string is skipped on validation of the serializer, therefore not included in the validated serializer data, and therefore not updated. See https://gist.github.com/mkemmerling/c6f532b31c8c41e9b5c8 . Does this help to clarify the problem? |
Actually, I gave this a try and my title was set to an empty string. Note that default is enforced at the DB level which means that if you're creating an instance with the Django shell without giving a title it'll be an empty string. |
This is a limitation of the html forms that would send an empty string where JSON data makes a difference between empty and null. Will have a look at your test case. Thanks for the details. |
I'm using version 3.2.3 (with Django 1.8.,4). The problem arises with the changes made for 3.2.0. And yes it occurs only with html forms where the Thanks again for having a look into this. |
ok, I had an issue in my DRF version and confirme I could reproduce your issue with the tutorial. |
Commit d231f36 to fix #3130 added the following check to
fields.Field.get_value()
:Maybe I am wrong, but it looks like with this change it is no longer possible to reset a
CharField
withallow_blank=True
but nodefault
argument which currently has a non-empty value back to an empty string: The default value for thedefault
argument is theempty
marker. Since thevalidate_empty_values()
method raises aSkipField
execption for this marker the field is skipped on update if set to an empty string.To work around this problem the field may be defined with the empty string as
default
argument, but to have bothallow_blank=True
anddefault=''
in the field's argument list seems counter-intuitive.The text was updated successfully, but these errors were encountered: