Skip to content
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

Breaks BooleanField with provided default value: can't save False via admin UI project-wide if using django-cassandra-engine in same project #90

Closed
ilia-khaustov opened this issue Apr 10, 2017 · 4 comments

Comments

@ilia-khaustov
Copy link

Found this issue while trying to use default kwarg with any BooleanField for any model in the project.

After setting default kwarg for model field, admin UI fails to update its value to False: changing False --> True is OK, but changing True --> False doesn't work. After some investigation found this most possible reason:

if (field_has_default and form.add_prefix(f.name) not in form.data and
            not getattr(form[f.name].field.widget,
                        'dont_use_model_field_default_for_empty_data', False)):
    continue

Condition above skips on BooleanField update when updating True --> False as field name is not present in form.data when widget value is not set (=False for CheckboxInput case). It is possible to override this behaviour by specifying widget.dont_use_model_field_default_for_empty_data = True for needed BooleanField, however, this looks like a poor workaround that should not be needed.

@srtonz
Copy link

srtonz commented Apr 24, 2017

It just took me way to long to grep for something monkeypatching django.forms.models.construct_instance. This is a critical issue as it breaks Django's admin form behavior.

@r4fek is it really necessary to change the behavior of django.forms.models.construct_instance in https://github.com/r4fek/django-cassandra-engine/blob/master/django_cassandra_engine/apps.py#L55 globally?

@r4fek r4fek closed this as completed in be330c8 Apr 24, 2017
@r4fek
Copy link
Owner

r4fek commented Apr 24, 2017

@geotob @ilya-khaustov could you guys try with current master? I think I fixed it, but need confirmation.

@srtonz
Copy link

srtonz commented Apr 26, 2017

@r4fek thanks, this seems to have fixed it. Would you be able to release a new version with the fix please?:)

@r4fek
Copy link
Owner

r4fek commented Apr 26, 2017

@geotob Version 1.1.1 released to PyPi. Enjoy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants