jaredly / jaredly/django-appsettings
Boolean setting with initial value set to False is breaking the system
- Dominant language
- Python
- Stars
- 88
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
It seems that either "val.initial = val.clean(val.initial)" is django overuse or there is an issue with django since quite long for BooleanField.
Meanwhile it might be useful not to use val.clean for BooleanField.
class BooleanField(Field):
widget = CheckboxInput
```
def to_python(self, value):
"""Returns a Python boolean object."""
# Explicitly check for the string 'False', which is what a hidden field
# will submit for False. Also check for '0', since this is what
# RadioSelect will provide. Because bool("True") == bool('1') == True,
# we don't need to handle that explicitly.
if value in ('False', '0'):
value = False
else:
value = bool(value)
value = super(BooleanField, self).to_python(value)
if not value and self.required:
raise ValidationError(self.error_messages['required'])
return value
```
To reproduce issue create appsettings group:
@register
class Offer:
as_download = False
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the registered Offer example with as_download=False and trace the BooleanField initialization path around val.initial = val.clean(val.initial). Compare that path with Django's BooleanField behavior and define done as preserving a false initial value without breaking the registered setting; no project file or test is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100