[Django] #36847: FileField(upload_to=...) callback no longer sees `auto_add_now` field

4 views
Skip to first unread message

Django

unread,
Jan 6, 2026, 11:26:50 AMJan 6
to django-...@googlegroups.com
#36847: FileField(upload_to=...) callback no longer sees `auto_add_now` field
----------------------------+-----------------------------------------
Reporter: Ran Benita | Type: Bug
Status: new | Component: Documentation
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-----------------------------------------
In Django 5.2 and before, accessing an `auto_add_now=True` DateTimeField
in the `upload_to` callback of a `FileField` was possible, i.e. the field
was filled with the current time. In Django 6.0, the field value is now
`None` (the field is not `null=True`).

It is not a big problem for me, since I just dropped the usage of
`auto_add_now` (I try to avoid it in new code anyway). But perhaps is can
be helpful to document in the changelog.

The
[https://docs.djangoproject.com/en/6.0/ref/models/fields/#django.db.models.FileField.upload_to
documentation of `upload_to`] currently states that the PK is not
available, maybe it can mention `auto_add_now` and friends as well.

{{{#!python
from django.db import models

def upload_to_callback(instance, filename):
return str(instance.created.year) # <- Crash, obj.created is None

class MyModel(models.Model):
created = models.DateTimeField(
auto_now_add=True,
)
file = models.FileField(
max_length=9999,
upload_to=upload_to_callback,
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36847>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 7, 2026, 3:39:08 AMJan 7
to django-...@googlegroups.com
#36847: FileField(upload_to=...) callback no longer sees `auto_add_now` field
-------------------------------------+-------------------------------------
Reporter: Ran Benita | Owner: Nashrh
| Ashraf Khan
Type: Bug | Status: assigned
Component: Documentation | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nashrh Ashraf Khan):

* owner: (none) => Nashrh Ashraf Khan
* status: new => assigned

Comment:

I can confirm this issue is reproducible.

Tested behavior:
- Django 5.2.x: `auto_now_add=True` DateTimeField is populated during the
`upload_to` callback.
- Django 6.0.x: the field value is None during `upload_to`, causing a
crash when accessed.

This appears to be a regression in Django 6.0, as the same code works
correctly in Django 5.2.
I will bisect to identify the commit where the behavior changed.
--
Ticket URL: <https://code.djangoproject.com/ticket/36847#comment:1>

Django

unread,
Jan 7, 2026, 4:03:20 AMJan 7
to django-...@googlegroups.com
#36847: FileField(upload_to=...) callback no longer sees `auto_add_now` field
-------------------------------------+-------------------------------------
Reporter: Ran Benita | Owner: Nashrh
| Ashraf Khan
Type: Bug | Status: assigned
Component: Documentation | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Nashrh Ashraf Khan):

Approach:

The save-order change in Django 6.0 appears intentional, and `upload_to`
callables are executed before fields populated during `Model.save()`
(e.g. `auto_now`, `auto_now_add`, and the primary key) are assigned
values.
Rather than changing the behavior, I plan to clarify this in the
documentation
and add a note to the Django 6.0 release notes.

I will submit a documentation-focused PR reflecting this.
--
Ticket URL: <https://code.djangoproject.com/ticket/36847#comment:2>

Django

unread,
Jan 7, 2026, 9:32:36 AMJan 7
to django-...@googlegroups.com
#36847: FileField(upload_to=...) callback no longer sees `auto_add_now` field
-------------------------------------+-------------------------------------
Reporter: Ran Benita | Owner: Nashrh
| Ashraf Khan
Type: Bug | Status: closed
Component: Documentation | Version: 6.0
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* resolution: => needsinfo
* status: assigned => closed

Comment:

Hi, thanks for the report.

I tried with a very similar model that I already had wired up with a view:

{{{#!py
def jtw(instance, filename):
assert instance.created

class TempFile(models.Model):
fileid = models.UUIDField(primary_key=True, default=uuid.uuid4)
path = models.FileField(upload_to=jtw)
created = models.DateTimeField(auto_now_add=True)
}}}

And testing both my view calling model.save() as well as the admin's add
form, gives me `AssertionError` for a missing `created` on all versions
back to 4.2.

Were you using a custom form?

> I will bisect to identify the commit where the behavior changed.

Nashrh, did you get a bisect result?

Happy to take another look when we have more info to advance the
investigation.
--
Ticket URL: <https://code.djangoproject.com/ticket/36847#comment:3>
Reply all
Reply to author
Forward
0 new messages