Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
python-version: '3.14'
cache: 'pip'
cache-dependency-path: 'docs/requirements.txt'
- name: Install system spell checker
run: sudo apt update && sudo apt install -y aspell aspell-en
- run: python -m pip install -r docs/requirements.txt
- name: Build docs
run: |
Expand Down
4 changes: 3 additions & 1 deletion django/db/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,9 @@ def _save_table(
].features.can_return_columns_from_insert
for field in insert_fields:
value = (
getattr(self, field.attname) if raw else field.pre_save(self, False)
getattr(self, field.attname)
if raw
else field.pre_save(self, add=True)
)
if hasattr(value, "resolve_expression"):
if field not in returning_fields:
Expand Down
5 changes: 3 additions & 2 deletions docs/internals/contributing/writing-documentation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ Spelling check
~~~~~~~~~~~~~~

Before you commit your docs, it's a good idea to run the spelling checker.
You'll need to install :pypi:`sphinxcontrib-spelling` first. Then from the
``docs`` directory, run:
You'll need to install :pypi:`sphinxcontrib-spelling` first. The spell checker
also requires a system-level spell checking backend such as `Aspell
<http://aspell.net/>`__. Then from the ``docs`` directory, run:

.. console::

Expand Down
4 changes: 2 additions & 2 deletions docs/internals/security.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ the industry-standard 90 days. Confirmed vulnerabilities with a
Reporting guidelines
--------------------

Include a runnable proof of concept
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Include a working proof of concept
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Please privately share a minimal Django project or code snippet that
demonstrates the potential vulnerability. Include clear instructions on how to
Expand Down
10 changes: 5 additions & 5 deletions docs/ref/models/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,11 @@ return type.

Built-in database functions (such as
:class:`~django.db.models.functions.Cast`) vary in whether arguments such
as ``output_field`` can be supplied positionally or only by keyword. For
``output_field`` and several other cases, the input ultimately reaches
``Func()`` as a keyword argument, so the advice to avoid constructing
keyword arguments from untrusted user input applies as equally to these
arguments as it does to ``**extra``.
as ``output_field`` can be supplied as positional arguments or only by
keyword. For ``output_field`` and several other cases, the input ultimately
reaches ``Func()`` as a keyword argument, so the advice to avoid
constructing keyword arguments from untrusted user input applies as equally
to these arguments as it does to ``**extra``.

``Aggregate()`` expressions
---------------------------
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/6.0.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ Bugfixes
to wrap below the changelist when filter elements contained long text
(:ticket:`36850`).

* Fixed a regression in Django 6.0 where ``auto_now_add`` field values were not
populated during ``INSERT`` operations, due to incorrect parameters passed to
``field.pre_save()`` (:ticket:`36847`).
4 changes: 2 additions & 2 deletions docs/releases/6.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Management Commands

* Management commands now set :class:`~argparse.ArgumentParser`\'s
``suggest_on_error`` argument to ``True`` by default on Python 3.14, enabling
suggestions for mistyped subcommand names and argument choices.
suggestions for incorrectly typed subcommand names and argument choices.

* The :djadmin:`loaddata` command now calls
:data:`~django.db.models.signals.m2m_changed` signals with ``raw=True`` when
Expand Down Expand Up @@ -340,7 +340,7 @@ Utilities
~~~~~~~~~

* :func:`~django.utils.dateparse.parse_duration` now supports ISO 8601
durations expressed in weeks (``PnW``).
time periods expressed in weeks (``PnW``).

Validators
~~~~~~~~~~
Expand Down
4 changes: 4 additions & 0 deletions docs/spelling_wordlist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ accessors
Aceh
admindocs
affordances
ai
Ai
Alchin
allowlist
Expand Down Expand Up @@ -245,6 +246,8 @@ kwargs
Kyrgyz
latin
lawrence
lexeme
lexemes
Libera
lifecycle
lifecycles
Expand Down Expand Up @@ -531,6 +534,7 @@ unapplied
unapplying
uncategorized
unclaim
unclosed
uncopyable
unencoded
unencrypted
Expand Down
10 changes: 10 additions & 0 deletions tests/model_fields/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,20 @@ class DataModel(models.Model):
# FileField


def upload_to_with_date(instance, filename):
return f"{instance.created_at.year}/{filename}"


class Document(models.Model):
myfile = models.FileField(storage=temp_storage, upload_to="unused", unique=True)


# See ticket #36847.
class DocumentWithTimestamp(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
myfile = models.FileField(storage=temp_storage, upload_to=upload_to_with_date)


###############################################################################
# ImageField

Expand Down
8 changes: 7 additions & 1 deletion tests/model_fields/test_filefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.test import TestCase, override_settings
from django.test.utils import isolate_apps

from .models import Document
from .models import Document, DocumentWithTimestamp


class FileFieldTests(TestCase):
Expand Down Expand Up @@ -209,3 +209,9 @@ class MyDocument(AbstractMyDocument):

document = MyDocument(myfile="test_file.py")
self.assertEqual(document.myfile.field.model, MyDocument)

def test_upload_to_callable_sees_auto_now_add_field_value(self):
d = DocumentWithTimestamp(myfile=ContentFile(b"content", name="foo"))
d.save()
self.assertIsNotNone(d.created_at)
self.assertIs(d.myfile.name.startswith(f"{d.created_at.year}/foo"), True)