summaryrefslogtreecommitdiff
path: root/django/contrib/contenttypes/fields.py
AgeCommit message (Collapse)Author
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.
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-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-09-18Refs #28586 -- Split descriptor from GenericForeignKey.Adam Johnson
This makes GenericForeignKey more similar to other fields which act as descriptors, preparing it to add “fetcher protocol” support in a clear and consistent way.
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-06-03Fixed #36060 -- Prevented IntegrityError in bulk_create() with ↵myoungjinGo-BE
order_with_respect_to.
2025-03-26Fixed #34819 -- Made GenericForeignKey prefetching use matching pk ↵Clifford Gama
representations. Ensured that rel_obj_attr and instance_attr return matching (pk, cls) tuples in GenericForeignKey.get_prefetch_queryset(), preventing mismatches when prefetching related objects where pk and get_prep_value() differ. Using value_to_string() also makes this code compatible with composite primary keys.
2025-02-03Fixed #36135 -- Fixed reverse GenericRelation prefetching.Simon Charette
The get_(local|foreign)_related_value methods of GenericRelation must be reversed because it defines (from|to)_fields and associated related_fields in the reversed order as it's effectively a reverse GenericForeignKey itself. The related value methods must also account for the fact that referenced primary key values might be stored as a string on the model defining the GenericForeignKey but as integer on the model defining the GenericRelation. This is achieved by calling the to_python method of the involved content type in get_foreign_related_value just like GenericRelatedObjectManager does. Lastly reverse many-to-one manager's prefetch_related_querysets should use set_cached_value instead of direct attribute assignment as direct assignment might are disallowed on ReverseManyToOneDescriptor descriptors. This is likely something that was missed in f5233dc (refs #32511) when the is_cached guard was added. Thanks 1xinghuan for the report.
2025-01-15Refs #33651 -- Removed Prefetch.get_current_queryset() and ↵Sarah Boyce
get_prefetch_queryset() per deprecation timeline.
2024-05-21Fixed #35405 -- Converted get_cache_name into a cached property in ↵Adam Johnson
FieldCacheMixin. FieldCacheMixin is used by related fields to track their cached values. This work migrates get_cache_name() to be a cached property to optimize performance by reducing unnecessary function calls when working with related fields, given that its value remains constant. Co-authored-by: Simon Charette <charette.s@gmail.com> Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
2024-02-20Fixed #35236 -- Used Field.attname/column attributes instead of ↵Adam Johnson
get_attname()/get_attname_column().
2024-02-19Fixed #35224 -- Made GenericForeignKey inherit from Field.Adam Johnson
2024-02-05Fixed #16281 -- Fixed ContentType.get_object_for_this_type() in a multiple ↵Ben Cail
database setup.
2023-09-18Fixed #33651 -- Added support for prefetching GenericForeignKey.Clément Escolano
Co-authored-by: revanthgss <revanthgss@almabase.com> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2023-09-08Fixed #34816 -- Fixed GenericForeignKey crash when checking cache for ↵Oguzhan Akan
primary keys with different types.
2022-11-18Fixed #26261 -- Fixed queryset crash when excluding reverse GenericRelation.roman_p
Thanks Amir Hadi for the report.
2022-11-09Fixed #34135 -- Added async-compatible interface to related managers.Jon Janzen
2022-11-08Fixed #34139 -- Fixed acreate(), aget_or_create(), and aupdate_or_create() ↵Jon Janzen
methods for related managers. Bug in 58b27e0dbb3d31ca1438790870b2b51ecdb10500.
2022-11-04Fixed #27654 -- Propagated alters_data attribute to callables overridden in ↵LightDiscord
subclasses. Thanks Shai Berger and Adam Johnson for reviews and the implementation idea.
2022-09-30Fixed #33984 -- Reverted "Fixed #32980 -- Made models cache related managers."Mariusz Felisiak
This reverts 4f8c7fd9d91b35e2c2922de4bb50c8c8066cbbc6 and adds two regression tests: - test_related_manager_refresh(), and - test_create_copy_with_m2m(). Thanks joeli for the report.
2022-07-27Refs #32948, Refs #32946 -- Used Q.create() internally for dynamic Q() objects.Nick Pope
Node.create() which has a compatible signature with Node.__init__() takes in a single `children` argument rather than relying in unpacking *args in Q.__init__() which calls Node.__init__(). In addition, we were often needing to unpack iterables into *args and can instead pass a list direct to Node.create().
2022-02-07Refs #33476 -- Reformatted code with Black.django-bot
2021-11-08Fixed #32980 -- Made models cache related managers.Keryn Knight
2021-11-03Fixed #32996 -- Cached PathInfos on relations.Keryn Knight
PathInfo values are ostensibly static over the lifetime of the object for which they're requested, so the data can be memoized, quickly amortising the cost over the process' duration.
2021-10-14Fixed #33008 -- Fixed prefetch_related() for deleted GenericForeignKeys.Martin Svoboda
Thanks Simon Charette for the implementation idea.
2021-07-28Refs #32946 -- Changed internal usage of dynamic Q() objects construction to ↵Keryn Knight
use non-kwargs initialization. This prefers non-kwargs construction of dynamically generated Q() objects to create a single Q() object instead of many and then combining them, where possible.
2021-07-22Fixed #32951 -- Removed Query.where_class & co.Nick Pope
Unused since 3caf957ed5eaa831a485abcb89f27266dbf3e82b.
2021-07-20Fixed #32944 -- Avoided unnecessary WhereNode.add() calls.Keryn Knight
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2020-12-29Used model's Options.label where applicable.Mariusz Felisiak
Follow up to b7a3a6c9ef0a89625881b47594120bca55fa2e49.
2020-09-25Fixed #32038 -- Fixed EmptyFieldListFilter crash with GenericRelation.Mariusz Felisiak
Thanks Javier Matos Odut for the report.
2020-02-04Simplified imports from django.db and django.contrib.gis.db.Nick Pope
2020-01-22Fixed #31190 -- Fixed prefetch_related() crash for GenericForeignKey with ↵Eugene Hatsko
custom ContentType foreign key. Regression in dffa3e1992562ba60512d96d1eb5859ffff2ceb5.
2019-05-31Fixed #30493 -- Fixed prefetch_related() for GenericRelation with different ↵can
content types. Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com> Thanks Simon Charette for the review.
2019-05-31Refs #30493 -- Added GenericRelatedObjectManager.get_content_type() hook.Mariusz Felisiak
2018-08-17Fixed #29612 -- Added GenericRelation prefetch_related() cache invalidation.Tom Forbes
2018-03-12Fixed #28988 -- Fixed queries when a GenericRelation is used with ↵robwa
multi-table inheritance.
2017-12-11Fixed #28909 -- Simplified code using tuple/list/set/dict unpacking.Nick Pope
2017-09-22Fixed #27332 -- Added FilteredRelation API for conditional join (ON clause) ↵Nicolas Delaby
support. Thanks Anssi Kääriäinen for contributing to the patch.
2017-09-07Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."Tim Graham
This reverts commit 550cb3a365dee4edfdd1563224d5304de2a57fda because try/except performs better.
2017-08-10Refs #16043 -- Refactored internal fields value cache.Paulo
* Removed all hardcoded logic for _{fieldname}_cache. * Added an internal API for interacting with the field values cache. Thanks carljm and MarkusH for support.
2017-07-21Fixed #28418 -- Fixed queryset crash when using a GenericRelation to a proxy ↵Rachel Tobin
model.
2017-06-28Fixed #27818 -- Replaced try/except/pass with contextlib.suppress().Mads Jensen
2017-06-05Replaced Model._get_pk_val() with pk property.Tim Graham
Model.pk was added after _get_pk_val() and many places weren't simplified.
2017-06-01Refs #23968 -- Removed unnecessary lists, generators, and tuple calls.Jon Dufresne
2017-04-27Refs #27795 -- Replaced many force_text() with str()Claude Paroz
Thanks Tim Graham for the review.
2017-02-03Fixed spelling of "nonexistent".Tim Graham
2017-02-01Refs #23919 -- Replaced kwargs.pop() with keyword-only arguments.Vytis Banaitis
2017-01-25Refs #23919 -- Replaced super(ClassName, self) with super().chillaranand