Opened 11 years ago
Closed 11 years ago
#22199 closed Bug (fixed)
Incorrect handling of max_length in FileField.deconstruct
Reported by: | Julian Brost | Owned by: | Andrew Godwin |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Release blocker | Keywords: | FileField, ImageField, max_length |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
max_length
is handled incorrectly in FileField.deconstruct
which results in all FileFields
created as VARCHAR(100)
in the database.
In order to reproduce the bug, just create a model like this:
class ExampleModel(models.Model): f = models.FileField(max_length=255)
Next run makemigrations
and migrate
. This will create a database table like this one:
CREATE TABLE "foo_examplemodel" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "f" varchar(100) NOT NULL);
The field f
has the wrong length which is the default value instead of the max_length
attribute passed to the FileField
constructor.
Attachments (1)
Change History (6)
by , 11 years ago
Attachment: | filefield-deconstruct-max-length.patch added |
---|
follow-up: 2 comment:1 by , 11 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
Severity: | Normal → Release blocker |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 11 years ago
Replying to bmispelon:
However, a full patch will also need some tests in order to get merged.
What exactly should such a testcase cover? Just this attribute for the FileField
class or for all Field
classes that support max_length
?
comment:3 by , 11 years ago
After a quick look, it seems this bug is only present for FileField
so you can probably only add a test for it.
However, it'd be useful to see whether we actually have any tests for this behavior and add some if that's not the case.
The problematic fields are those that set a value for max_length
in their __init__()
method:
EmailField
(this one might be special-cased. see 48493cff73fd01870306965f1c48193602754a78)FilePathField
IPAddressField
GenericIPAddressField
(you should be able to simplify thedeconstruct()
method on this one sincemax_length
is always set to 39)SlugField
URLField
- And of course,
FileField
.
comment:4 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Hi,
This does appear to be a problem and your patch seems like it fixes the issue.
However, a full patch will also need some tests in order to get merged.
Thanks.