#36847: FileField(upload_to=...) callback no longer sees `auto_now_add ` field
-------------------------------------+-------------------------------------
Reporter: Ran Benita | Owner: Nashrh
| Ashraf Khan
Type: Bug | Status: closed
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Release blocker | Resolution: needsinfo
Keywords: upload_to, | Triage Stage: Accepted
auto_now_add, pre_save |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Nashrh Ashraf Khan):
Replying to [comment:3 Jacob Walls]:
> 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.
Hi,
Thanks Jacob. Ran Benita was able to bisect this to commit
94680437a45a71c70ca8bd2e68b72aa1e2eff337 which introduced the regression.
After reviewing the bisected commit and the discussion, I agree this is a
regression introduced by 94680437a45a71c70ca8bd2e68b72aa1e2eff337.
The insert path now calls field.pre_save(..., add=False) which prevents
auto_now_add from populating values before upload_to() runs.
Restoring add=True in Model._save_table appears consistent with historical
behavior and avoids order-dependent failures.
I’m preparing a patch with a regression test.
--
Ticket URL: <https://code.djangoproject.com/ticket/36847#comment:13>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019b9ca25466-43754c6c-5e89-4f8d-9d05-4d9910e1ee61-000000%40eu-central-1.amazonses.com.