summaryrefslogtreecommitdiff
path: root/django/db/models/fields
AgeCommit message (Collapse)Author
2026-10-23Refs #30949 -- Replaced django.utils.functional.cached_property with ↵Jacob Rief
functools.cached_property. Since Python 3.12, `functools.cached_property` no longer takes a lock (https://github.com/python/cpython/issues/87634), which was the main objection to using it instead of Django's own implementation. `Prefetch(to_attr=...)` and the admindocs model detail page now accept `functools.cached_property` as well as Django's own `cached_property`. Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
2026-10-13Refs #32980 -- Avoided unnecessary router and connection lookups for reverse ↵Tim Kedmenec
FKs. These do not need to be looked up if the value is truthy.
2026-10-13Fixed #32980 -- Optimized ManyRelatedManager.__init__().Jacob Walls
Many attributes did not vary with the instance, so they did not need to be calculated during __init__(). Thanks Tim Kedmenec for raising the issue at: https://forum.djangoproject.com/t/46178
2026-10-08Fixed #37403 -- Fixed JSONField __in crash on SQLite with Value(None) ↵Clifford Gama
expressions. Regression in 9b8e4c6d7d47f7b2e96817ba334e9fd53c10a0df.
2026-10-07Refs #37297 -- Prevented crash on JSONField __isnull lookups on Oracle when ↵Clifford Gama
a key is outside its integer range. Oracle's JSON_EXISTS() rejects an array-subscript literal this long with ORA-40598/JZN-00211.
2026-10-07Fixed #37297 -- Prevented crash on JSONField key lookups when an integer key ↵Clifford Gama
is outside PostgreSQL's int4 range.
2026-10-05Fixed #37377 -- Fixed JSONField __in crash/wrong result for Value() primitives.Clifford Gama
Refs #36689. 9b8e4c6d7d wrapped every Value() rhs param of a JSONIn lookup in JSON_EXTRACT()/JSON_VALUE() assuming it was already JSON-serialized. That only holds for Value(..., JSONField()); a bare Value("primitive") gets an inferred non-JSON output_field (e.g. CharField), so its compiled param was a raw primitive, not JSON text. JSONIn.resolve_expression_parameter() now JSON-encodes the Value's raw .value itself whenever its output_field isn't JSONField. As a side effect, this also fixes Value(True)/Value(False) in __in, which were previously compared as raw Python bools against the JSON-extracted lhs and never matched. Thanks Jacob Walls for the report. Regression in 9b8e4c6d7d47f7b2e96817ba334e9fd53c10a0df. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
2026-09-30Fixed #37291 -- Prevented tuple lookups from hanging on F() expressions.Yassin Bahri
The underlying unsafety with iterating F() expressions will be handled later (#37384), to allow time to consider backward compatibility. The underlying query should also not raise a ValueError (#37383), but that likely will not be backported. Thanks Pravin Kamble for the review. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
2026-09-18Fixed #37339 -- Allowed ipaddress objects in GenericIPAddressField.Thibaut Decombe
get_prep_value() tested for ":" before coercing the value to a string, which crashed with a TypeError for non-string values such as ipaddress.IPv4Address and ipaddress.IPv6Address instances, even though to_python() accepts them.
2026-09-17Fixed #37348 -- Reverted "Fixed #36806 -- Added system check for null kwarg ↵Natalia
in GeneratedField.". This reverts commit 6025eab3c509b4de922117e16866bbfe0ee99aa6, includes a release note for 6.1.2, and keeps fields.W225 documented as removed. Thanks to Michal Porteš for the report, and to Jacob Walls and Simon Charette for reviews.
2026-09-03Refs #37293 -- Aliased RemovedInDjango70Warning to RemovedInDjango2028Warning.Carlton Gibson
Updated references to RemovedInDjango70Warning to use the new warning, and adjusted references to "Django 7.0" to "Django 2028". RemovedInDjango70Warning remains importable as an alias of the same class, so existing warning filters and except clauses in third-party code keep working across the rename.
2026-08-31Fixed #37237 -- Improved RelatedIn lookup preparation performance.Mariano Baragiola
Thanks Simon Charette for the implementation idea.
2026-08-31Fixed #37300 -- Preserved parent instance hints on custom Prefetch querysets.Yassin Bahri
Regression in 821619aa8771ef211c4c4922001efdf914201ca3. Thanks Norbert Kwizera for the report.
2026-08-14Fixed #37260 -- Made alterations between Python on_delete options noops.Adam Johnson
Support for database-level delete options removed "on_delete" from `Field.non_db_attrs` because changes to or from the new `DB_CASCADE`, `DB_SET_DEFAULT`, and `DB_SET_NULL` options require schema changes. As a consequence, an `AlterField` changing only a Python-level `on_delete` option (such as `CASCADE` to `PROTECT`) performs unnecessary schema changes when it was previously a no-op at the database level. This commit makes `ForeignObject.non_db_attrs` a property that includes `"on_delete"`only when the option is not a database-level one, so that: - Python-level to Python-level changes skip DDL again, - changes to, from, or between database-level options still alter the field. Regression in 0c487aa3a7b2417481bf48c1e5355c855873e210.
2026-08-14Fixed #37273 -- Allowed F() expressions on the RHS of CompositePK lookups.Pravin Kamble
2026-08-13Fixed #37254 -- Added fields.E323 for models referenced by ManyToManyFields.Mariusz Felisiak
Thanks Jacob Walls and Sarah Boyce for reviews.
2026-06-10Fixed #37142 -- Moved django_file_prefixes() to django.utils.warnings.zhengkangyang
2026-05-05Fixed #37053 -- Added validate=True to base64.b64decode() calls.Sarah Boyce
2026-04-22Fixed #35870 -- Made blank choice label in forms more accessible.Annabelle Wiegart
Added new constant django.db.models.fields.BLANK_CHOICE_LABEL for an accessible and translatable blank choice label in forms. Deprecated django.db.models.fields.BLANK_CHOICE_DASH constant. Added the immediately deprecated transitional setting USE_BLANK_CHOICE_DASH. Co-Authored-By: Marijke Luttekes <mail@marijkeluttekes.dev>
2026-04-14Fixed #27150 -- Made base File objects truthy by default.VIZZARD-X
2026-04-02Fixed #36973 -- Made fields.E348 check detect further clashes between ↵Clifford Gama
managers and related_names. Clashes were only detected for self-referential relationships, i.e. ForeignKey("self"). Refs #22977. Bug in 6888375c53476011754f778deabc6cdbfa327011. Thanks JaeHyuckSa for the thorough review!
2026-03-24Refs #36494 -- Prevented crash in JSONField numeric lookups with expressions.Vignesh Anand
2026-03-18Fixed #36987 -- Observed prepared argument in UUIDField.get_db_prep_value().Jacob Walls
This avoids two isinstance() calls per UUID value.
2026-03-13Fixed #36927 -- Optimized Field.deconstruct().Adam Johnson
2026-03-12Fixed #36727 -- Deprecated Field.get_placeholder in favor of ↵Simon Charette
get_placeholder_sql. The lack of ability of the get_placeholder call chain to return SQL and parameters separated so they can be mogrified by the backend at execution time forced implementations to dangerously interpolate potentially user controlled values. The get_placeholder_sql name was chosen due to its proximity to the previous method, but other options such as Field.as_sql were considered but ultimately rejected due to its different input signature compared to Expression.as_sql that might have lead to confusion. There is a lot of overlap between what Field.get_db_prep_value and get_placeholder_sql do but folding the latter in the former would require changing its return signature to return expression which is a way more invasive change than what is proposed here. Given we always call get_db_prep_value it might still be an avenue worth exploring in the future to offer a publicly documented interface to allow field to take an active part in the compilation chain. Thanks Jacob for the review.
2026-03-11Refs #28455 -- Avoided QuerySet cloning for Prefetch() when queryset is not ↵Keryn Knight
provided. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2026-03-11Refs #28455 -- Avoided QuerySet cloning in simple prefetch_related() usages.Keryn Knight
manager.get_queryset() always returns freshly instantiated per-instance QuerySet which doesn't need subsequent cloning. Based on work originally done by Anssi Kääriäinen and Tim Graham.
2026-03-02Refs #35381 -- Moved JSONNull to django.db.models.expressions.Clifford Gama
2026-01-12Fixed #36858 -- Optimized `Field._get_default()` for `db_default` case.Adam Johnson
Create and share a single instance of `DatabaseDefault` instead of making a new one each time the lambda is called. The quick benchmark on the ticket shows a ~12% speedup for a large `bulk_create()` operation.
2025-12-28Refs #24920 -- Made DecimalField system checks database dependent.Mariusz Felisiak
Thanks Tim Graham for the suggestion.
2025-12-22Fixed #36508 -- Interpreted __iexact=None on KeyTransforms as __exact=None.Clifford Gama
Thanks Jacob Walls for the report.
2025-12-22Fixed #36806 -- Added system check for null kwarg in GeneratedField.Nilesh Kumar Pahari
The null argument has no effect on GeneratedField since the nullability of the column depends on the database and expression used.
2025-12-17Fixed #27380 -- Added "raw" argument to m2m_changed signals.Mariusz Felisiak
2025-12-17Refs #27380 -- Added ManyRelatedManager.set_base() hook.Mariusz Felisiak
2025-12-17Refs #27380 -- Made ManyRelatedManager.set() use *_base() hooks.Mariusz Felisiak
2025-12-17Refs #27380 -- Made ManyRelatedManager.add()/clear()/remove() implementation ↵Mariusz Felisiak
more consistent. This also adds _add_base(), _clear_base(), and _remove_base() internal hooks.
2025-12-10Refs #36689 -- Serialized JSONIn rhs parameters wrapped in Value expressions.Clifford Gama
2025-12-10Fixed #36689 -- Fixed top-level JSONField __in lookup failures on MySQL and ↵Clifford Gama
Oracle. Added a JSONIn lookup to handle correct serialization and extraction for JSONField top-level __in queries on backends without native JSON support. KeyTransformIn now subclasses JSONIn. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com> Thanks Jacob Walls for the report and review.
2025-12-05Fixed #36722 -- Moved AutoFieldMixin validate_autopk_value() check to ↵Clifford Gama
get_db_prep_save. The validation in validate_autopk_value is specific to saving. Having it in get_db_prep_value caused Value(0, AutoField()) to fail unexpectedly when used in a filter on MySQL. Thanks Jacob Walls for the review.
2025-11-23Refs #21961 -- Added DatabaseFeatures.supports_on_delete_db_(cascade/null) ↵Tim Graham
feature flags. Needed on MongoDB. Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2025-11-19Fixed #26609 -- Extended fields.E004 system check for unordered iterables.Mariusz Felisiak
Co-authored-by: Karl Wooster <karl.wooster@alleima.com>
2025-11-17Fixed #24920 -- Added support for DecimalField with no precision.Mariusz Felisiak
Thanks Lily for the review.
2025-11-12Refs #35381 -- Made JSONNull deconstruct using convenient import path.Clifford Gama
2025-10-29Refs #35381 -- Deprecated using None in JSONExact rhs to mean JSON null.Clifford Gama
Key and index lookups are exempt from the deprecation. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
2025-10-29Fixed #35381 -- Added JSONNull() expression.Clifford Gama
Thanks Jacob Walls for the review.
2025-10-29Refs #35972 -- Returned params in a tuple in further lookups.Jacob Walls
2025-10-18Fixed #21961 -- Added support for database-level delete options for ForeignKey.Mariusz Felisiak
Thanks Simon Charette for pair programming. Co-authored-by: Nick Stefan <NickStefan12@gmail.com> Co-authored-by: Akash Kumar Sen <71623442+Akash-Kumar-Sen@users.noreply.github.com> Co-authored-by: Simon Charette <charette.s@gmail.com>
2025-10-16Refs #28586 -- Copied fetch modes to related objects.Adam Johnson
This change ensures that behavior and performance remain consistent when traversing relationships.
2025-10-16Refs #28586 -- Simplified related descriptor get_queryset() methods.Adam Johnson
Modify these methods to accept an instance parameter which is clearer and allows us to set the instance hint earlier.
2025-10-16Fixed #28586 -- Added model field fetch modes.Adam Johnson
May your database queries be much reduced with minimal effort. co-authored-by: Andreas Pelme <andreas@pelme.se> co-authored-by: Simon Charette <charette.s@gmail.com> co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>