Opened 4 years ago

Closed 4 years ago

#27186 closed Bug (fixed)

Cannot change CheckboxSelectMultiple, FileInput, MultiWidget, SplitDateTimeWidget, and SelectDateWidget with model field default since Django 1.10.1

Reported by: Michael Käufl Owned by: Tim Graham
Component: Forms Version: 1.10
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Michael Käufl)

Since Django 1.10.1 (it worked in 1.10.0), it is not possible to change the value of a DateTimeField in the admin if the field has a default.

Changing the value and saving the object results in the old value still being in the database.

How to reproduce

I created a small example project to easily reproduce the problem.

It has a model ''Dummy'' with two DateTimeFields. One with and one without a default (django.utils.timezone.now). The admin is the default django.contrib.admin.ModelAdmin.

git clone https://github.com/michael-k/datetimefieldbroken.git && cd datetimefieldbroken
docker-compose build --pull
docker-compose run web migrate
docker-compose run web createsuperuser
docker-compose up -d

Head your browser to http://localhost:8023/admin/main/dummy/add/, login and create a new Dummy using Save and continue editing. Change the values all for input fields and press Save and continue editing again. The values of Dt with default are unchanged.

Patch that introduced the issue

We believe that PR 7068 (regarding issue 27039) introduced the problem, but did not validate this. Supposedly this happens because DateTimeField is split into two fields (date + time) in the admin.

We tried it however with Django 1.10.0 and it works just fine.

Change History (13)

comment:1 Changed 4 years ago by Michael Käufl

Description: modified (diff)

comment:2 Changed 4 years ago by Michael Käufl

Description: modified (diff)

comment:3 Changed 4 years ago by Tim Graham

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:4 Changed 4 years ago by Tim Graham

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:5 Changed 4 years ago by Tim Graham

Has patch: set

comment:6 Changed 4 years ago by Tim Graham

Summary: Cannot change DateTimeField with default via Admin since Django 1.10.1Cannot change FileInput, MultiWidget, SplitDateTimeWidget, and SelectDateWidget with model field default since Django 1.10.1

comment:7 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 3507d4e7:

Fixed #27186 -- Fixed model form default fallback for MultiWidget, FileInput, SplitDateTimeWidget, SelectDateWidget, and SplitArrayWidget.

Thanks Matt Westcott for the review.

comment:8 Changed 4 years ago by Tim Graham <timograham@…>

In 0b59ea33:

[1.10.x] Fixed #27186 -- Fixed model form default fallback for MultiWidget, FileInput, SplitDateTimeWidget, SelectDateWidget, and SplitArrayWidget.

Thanks Matt Westcott for the review.

Backport of 3507d4e773aa9ff2336e7230ba231c4ba6eb568f from master

comment:9 Changed 4 years ago by Tim Graham

Has patch: unset
Resolution: fixed
Status: closednew
Summary: Cannot change FileInput, MultiWidget, SplitDateTimeWidget, and SelectDateWidget with model field default since Django 1.10.1Cannot change CheckboxSelectMultiple, FileInput, MultiWidget, SplitDateTimeWidget, and SelectDateWidget with model field default since Django 1.10.1

As reported in #27291, CheckboxSelectMultiple is also affected.

comment:10 Changed 4 years ago by Tim Graham

Has patch: set

PR for CheckboxSelectMultiple.

comment:11 Changed 4 years ago by GitHub <noreply@…>

In 87c5e7e:

Refs #27186 -- Fixed model form default fallback for CheckboxSelectMultiple.

comment:12 Changed 4 years ago by Tim Graham <timograham@…>

In f23c03e:

[1.10.x] Refs #27186 -- Fixed model form default fallback for CheckboxSelectMultiple.

Backport of 87c5e7efebd040aef0f0479ccf86877155bb5cea from master

comment:13 Changed 4 years ago by Tim Graham

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top