Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#27805 closed Bug (fixed)

ClearableFileInput's "Clear" checkbox on model fields with a default doesn't work

Reported by: Mario J. Barchéin Molina Owned by: Tim Graham
Component: Forms Version: 1.10
Severity: Release blocker Keywords: FileField, ModelForm, ClearableFileInput
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Checking 'clear' in a FileField and saving the ModelForm doesn't set None in model's attribute.

This is broken from 1.10.2 to 1.10.x and 1.11a1. Works in 1.9.x and 1.10.1

I attach a simple project "polls" with only one model (TestModel) and admin zone. To reproduce the problem:

1) Log in in admin zone in http://localhost:8000/admin/polls/testmodel/ with user "admin" and password "adminadmin"
2) Create a new "Test Model" with an image
3) Edit the created "Test Model" instance, check "clear" checkbox and submit form

The expected behaviour is having model with no image but this doesn't happen.

Attachments (1)

testproject.tar.gz (7.2 KB) - added by Mario J. Barchéin Molina 3 years ago.
test project with sqlite database

Download all attachments as: .zip

Change History (6)

Changed 3 years ago by Mario J. Barchéin Molina

Attachment: testproject.tar.gz added

test project with sqlite database

comment:1 Changed 3 years ago by Tim Graham

Component: UncategorizedForms
Owner: changed from nobody to Tim Graham
Severity: NormalRelease blocker
Status: newassigned
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:2 Changed 3 years ago by Tim Graham

Has patch: set
Summary: clear checkbox in FileField doesn't workClearableFileInput's "Clear" checkbox on model fields with a default doesn't work

I'm not sure if default=None is accomplishing anything for your use case, but removing it would solve the issue until the fix is released.

PR

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

Resolution: fixed
Status: assignedclosed

In 4353640e:

Fixed #27805 -- Fixed ClearableFileInput's "Clear" checkbox on model fields with a default.

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

In 2b17e477:

[1.11.x] Fixed #27805 -- Fixed ClearableFileInput's "Clear" checkbox on model fields with a default.

Backport of 4353640ea9495d58fabd0357253b82de3b069408 from master

comment:5 Changed 3 years ago by Tim Graham <timograham@…>

In cd69ac06:

[1.10.x] Fixed #27805 -- Fixed ClearableFileInput's "Clear" checkbox on model fields with a default.

Backport of 4353640ea9495d58fabd0357253b82de3b069408 from master

Note: See TracTickets for help on using tickets.
Back to Top