Opened 9 years ago

Closed 9 years ago

#24368 closed Uncategorized (wontfix)

FileField needlessly serializes upload_to

Reported by: Roman Odaisky Owned by: nobody
Component: Migrations Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Roman Odaisky)

django.db.models.fields.FileField explicitly includes upload_to in the serialization process. This takes no part in the actual migration process but causes errors if the value of the field is a lambda function. Instead, the deconstruct() functions for FileField and other fields should only serialize arguments relevant to subsequent ALTER commands issued to the DBMS.

Once fixed, #22351 can be reverted.

Change History (3)

comment:1 by Roman Odaisky, 9 years ago

Description: modified (diff)
Summary: FileField needlessly serializes upload_to; same problems with some other fieldsFileField needlessly serializes upload_to

comment:2 by Roman Odaisky, 9 years ago

Alternatively, a better way might be to serialize lambdas to something that raises NotImplementedError. Also, given that upload_to and other fields might matter in case migrations contain RunPython blocks, a warning could be appropriate if both unserializable non-essential fields and RunPython are encountered.

Anything would be preferable to the current situation.

comment:3 by Tim Graham, 9 years ago

Resolution: wontfix
Status: newclosed

The documentation describes why options like upload_to are serialized:

Django will make migrations for any change to your models or fields - even options that don’t affect the database - as the only way it can reconstruct a field correctly is to have all the changes in the history, and you might need those options in some data migrations later on (for example, if you’ve set custom validators).

I'm not convinced that allowing lambdas for some options where it may not be needed (like upload_to), but not in other places where it is needed (like default) would be a good situation. Could you please raise the issue on the DevelopersMailingList if you think it merits further discussion? Thank-you.

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