Opened 13 hours ago

Closed 11 hours ago

#35948 closed New feature (wontfix)

FileField storage should support lambda

Reported by: Alexander Nestorov Owned by:
Component: File uploads/storage Version: 5.1
Severity: Normal Keywords: storage, lambda
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Since Django already supports callables for the storage parameter of FileField, it would be nice if it also supported lambdas.
Currently, attempting to use lambda will result in the following error:

 File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/makemigrations.py", line 259, in handle
    self.write_migration_files(changes)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/makemigrations.py", line 364, in write_migration_files
    migration_string = writer.as_string()
                       ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/writer.py", line 141, in as_string
    operation_string, operation_imports = OperationWriter(operation).serialize()
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/writer.py", line 99, in serialize
    _write(arg_name, arg_value)
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/writer.py", line 51, in _write
    arg_string, arg_imports = MigrationWriter.serialize(item)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/writer.py", line 287, in serialize
    return serializer_factory(value).serialize()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/serializer.py", line 51, in serialize
    item_string, item_imports = serializer_factory(item).serialize()
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/serializer.py", line 240, in serialize
    return self.serialize_deconstructed(path, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/serializer.py", line 105, in serialize_deconstructed
    arg_string, arg_imports = serializer_factory(arg).serialize()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/serializer.py", line 185, in serialize
    raise ValueError("Cannot serialize function: lambda")

https://docs.djangoproject.com/en/5.1/topics/files/#using-a-callable

Change History (1)

comment:1 by Tim Graham, 11 hours ago

Resolution: wontfix
Status: newclosed

They were supported until Django added migrations support. See #21037 and #24368 for background on the decision-making.

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