diff options
| author | Simon Charette <charette.s@gmail.com> | 2025-01-25 00:12:17 -0500 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-02-03 10:40:52 +0100 |
| commit | 303c2569dad4e3222e94fc5b76dc7b83b35fde17 (patch) | |
| tree | 0ca5414d69e009fd5e7eb8d6966e5ac0c4ce3746 /tests/admin_views/tests.py | |
| parent | affad13d0c56184e2089cd7e8ecd80dd4217f6c4 (diff) | |
[5.2.x] Fixed #36135 -- Fixed reverse GenericRelation prefetching.
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.
Backport of 198b30168d4e94af42e0dc7967bd3259b5c5790b from main.
Diffstat (limited to 'tests/admin_views/tests.py')
0 files changed, 0 insertions, 0 deletions
