summaryrefslogtreecommitdiff
path: root/django/db/models/fields
AgeCommit message (Collapse)Author
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>
2025-10-15Fixed 36622 -- Prevented LazyObject FileField storages from evaluating at ↵Clifford Gama
boot time. Co-authored-by: Fabien MICHEL <fmichel@adista.fr>
2025-09-23Fixed #36616 -- Added DatabaseOperations.adapt_durationfield_value().Tim Graham
2025-09-22Fixed #35453 -- Made ManyToManyField.concrete False.Ryan P Kilby
ManyToManyField was already excluded from fields, concrete_fields, and local_concrete_fields in Options.
2025-09-22Fixed #36612 -- Fixed a KeyTextTransform crash on MySQL against annotations.Simon Charette
MySQL only supports the ->> when used directly against columns, this can be inferred by the presence of lhs.output_field.model as model bounds fields are directly tied to columns. Purposely don't systematically switch to using JSON_QUOTE(JSON_EXTRACT(...)) as there might be functional indices out there that rely on the SQL remaining stable between versions. Thanks Jacob Tavener for the report.
2025-09-14Refs #27222 -- Refreshed GeneratedFields values on save() initiated update.Simon Charette
This required implementing UPDATE RETURNING machinery that heavily borrows from the INSERT one.
2025-08-23Refs #470 -- Adjusted Field.db_returning to be backend agnostic.Simon Charette
Determining if a field is db_returning based on the default connection feature availability prevents the usage of RETURNING for db_default fields in setups where non-default backends do support RETURNING. Whether or not the field should be attempted to be returned is already checked at the compiler level which is backend aware.
2025-08-07Fixed #36210, Refs #36181 -- Allowed Subquery usage in further lookups ↵Jacob Walls
against composite pks. Follow-up to 8561100425876bde3be4b2a22324655f74ff9609. Co-authored-by: Simon Charette <charette.s@gmail.com>
2025-08-05Fixed #36530 -- Extended fields.E347 to check for ManyToManyField involving ↵jkhall81
CompositePrimaryKey on either side. Thanks to Jacob Walls for the report.
2025-07-28Fixed #36522 -- Added support for filtering composite pks using a tuple of ↵Simon Charette
expressions. Thanks Jacob Walls for the report, and Sarah Boyce and Mariusz Felisiak for reviews.
2025-07-23Refs #36500 -- Corrected rewrapped long lines fixed via a script.Mike Edmunds
Manually reformatted some comments and docstrings where autofix_w505.py changed the meaning of the formatting.
2025-07-23Refs #36500 -- Rewrapped long docstrings and block comments via a script.django-bot
Rewrapped long docstrings and block comments to 79 characters + newline using script from https://github.com/medmunds/autofix-w505.
2025-07-23Removed double spaces after periods and within phrases.Sarah Boyce
2025-07-22Fixed #36282 -- Used prefetched values in ForwardManyToOneDescriptor from ↵Take Weiland
indirect ancestors. When looking for cached values in ManyRelatedManager and ForwardManyToOneDescriptor walk up the whole chain of ancestors (as long as they are cached) to find the prefetched relation.
2025-07-09Fixed typo in ReverseManyToOneDescriptor docstring.tinmarbusir
2025-06-30Fixed #36464 -- Fixed "__in" tuple lookup on backends lacking native support.Simon Charette
When native support for tuple lookups is missing in a DB backend, it can be emulated with an EXISTS clause. This is controlled by the backend feature flag "supports_tuple_lookups". The mishandling of subquery right-hand side in `TupleIn` (added to support `CompositePrimaryKey` in Refs #373) was likely missed because the only core backend we test with the feature flag disabled (Oracle < 23.4) supports it natively. Thanks to Nandana Raol for the report, and to Sarah Boyce, Jacob Walls, and Natalia Bidart for reviews.
2025-06-04Fixed #36432 -- Fixed a prefetch_related crash on related target subclass ↵Simon Charette
queryset. Regression in 626d77e52a3f247358514bcf51c761283968099c. Refs #36116. Thanks Cornelis Poppema for the excellent report.
2025-05-14Refs #36085 -- Moved compile_json_path to BaseDatabaseOperations.hesham942
2025-04-03Fixed #36290 -- Made TupleIn() lookup discard tuples containing None.Simon Charette
Just like the In() lookup discards of None members TupleIn() should discard tuples containing any None as NULL != NULL in SQL and the framework expects such queries to be elided under some circumstances. Refs #31667, #36116. Thanks Basptise Mispelon for bisecting the regression to 626d77e.