﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35657	Specifying db_default on FileField causes crash on instance save	David Sanders	Sarah Boyce	"I guess there's the existential question: ""Does db_default make sense with FileField/ImageField?""  Perhaps, as long as there's a file at the path defined by the `db_default` expression? 🤔

In any case when defined with a `FileField`, the presence of `DatabaseDefault` as the field's value causes a crash:

Given the model:

{{{
class Foo(models.Model):
    bar = models.FileField(db_default=""path/to/file.txt"")
}}}

We get `AttributeError` exceptions when attempting to create an instance:

{{{
>>> Foo.objects.create()
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
  File ""/path/to/django/django/db/models/manager.py"", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""/path/to/django/django/db/models/query.py"", line 660, in create
    obj.save(force_insert=True, using=self.db)
  File ""/path/to/django/django/db/models/base.py"", line 891, in save
    self.save_base(
  File ""/path/to/django/django/db/models/base.py"", line 997, in save_base
    updated = self._save_table(
              ^^^^^^^^^^^^^^^^^
  File ""/path/to/django/django/db/models/base.py"", line 1160, in _save_table
    results = self._do_insert(
              ^^^^^^^^^^^^^^^^
  File ""/path/to/django/django/db/models/base.py"", line 1201, in _do_insert
    return manager._insert(
           ^^^^^^^^^^^^^^^^
  File ""/path/to/django/django/db/models/manager.py"", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""/path/to/django/django/db/models/query.py"", line 1828, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""/path/to/django/django/db/models/sql/compiler.py"", line 1847, in execute_sql
    for sql, params in self.as_sql():
                       ^^^^^^^^^^^^^
  File ""/path/to/django/django/db/models/sql/compiler.py"", line 1770, in as_sql
    value_rows = [
                 ^
  File ""/path/to/django/django/db/models/sql/compiler.py"", line 1771, in <listcomp>
    [
  File ""/path/to/django/django/db/models/sql/compiler.py"", line 1772, in <listcomp>
    self.prepare_value(field, self.pre_save_val(field, obj))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""/path/to/django/django/db/models/sql/compiler.py"", line 1720, in pre_save_val
    return field.pre_save(obj, add=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""/path/to/django/django/db/models/fields/files.py"", line 320, in pre_save
    if file.name is None and file._file is not None:
       ^^^^^^^^^
AttributeError: 'DatabaseDefault' object has no attribute 'name'
}}}"	Bug	closed	Database layer (models, ORM)	5.0	Release blocker	fixed	db_default		Ready for checkin	1	0	0	0	0	0
