Last active
October 11, 2022 12:17
-
-
Save apinsard/9aafbcc3c4bb24d4732c6ed0f6c9bc36 to your computer and use it in GitHub Desktop.
Example of QuerySet._result_cache not set when calling QuerySet.__repr__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> a = Tag.objects.filter(pk=1) | |
>>> a._result_cache | |
>>> a | |
<QuerySet [<Tag: Test>]> | |
>>> a._result_cache | |
>>> for b in a: | |
... pass | |
... | |
>>> a._result_cache | |
[<Tag: Test>] | |
>>> | |
>>> from django.utils.functional import cached_property | |
>>> class X: | |
... @cached_property | |
... def tags(self): | |
... return Tag.objects.filter(pk=1) | |
... | |
>>> x = X() | |
>>> x.tags._result_cache | |
>>> x.tags | |
<QuerySet [<Tag: Test>]> | |
>>> x.tags._result_cache | |
>>> for y in x.tags: | |
... pass | |
... | |
>>> x.tags._result_cache | |
[<Tag: Test>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment