#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.

-- 
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/0107019b9421d9a4-e92b905b-6dab-4927-b1ab-16d51c2eef3b-000000%40eu-central-1.amazonses.com.

Reply via email to