diff options
| author | Keryn Knight <keryn@kerynknight.com> | 2021-08-05 19:11:14 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-11-03 11:27:04 +0100 |
| commit | a697424969f7f464bf6492b09a6cdac135499e02 (patch) | |
| tree | 179e1165bc361e3fe8b822135790ea971449a4d4 /django/db/models/sql/query.py | |
| parent | 3ff7b15bb79f2ee5b7af245c55ae14546243bb77 (diff) | |
Fixed #32996 -- Cached PathInfos on relations.
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.
Diffstat (limited to 'django/db/models/sql/query.py')
| -rw-r--r-- | django/db/models/sql/query.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 171e72cfb8..2c5f11cbbf 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1528,8 +1528,11 @@ class Query(BaseExpression): path.extend(path_to_parent) cur_names_with_path[1].extend(path_to_parent) opts = path_to_parent[-1].to_opts - if hasattr(field, 'get_path_info'): - pathinfos = field.get_path_info(filtered_relation) + if hasattr(field, 'path_infos'): + if filtered_relation: + pathinfos = field.get_path_info(filtered_relation) + else: + pathinfos = field.path_infos if not allow_many: for inner_pos, p in enumerate(pathinfos): if p.m2m: |
