New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
select_sublcasses does not work with prefetch_related #110
Comments
I wouldn't be entirely surprised to find that the I assume from your opening the ticket that |
If |
Yes, it does not work in the expected by me way when When I execute the following:
The following 3 SQL queries are executed:
It looks like the first query finds that there are
|
The fact they're not cached may, tentatively be related to the solution proposed in #78. |
Probably, you are right regarding the Anyway, executing the following
results in 3 SQL queries which is an issue from my point of view. |
Hi @Anislav, thanks for the report. I think @kezabelle is likely correct that #78 would fix the reverse-related cache, which seems like part of the fix needed here. Regarding the three queries, I'm not sure what's going on there, would need to dig into it. Probably won't have time to do that soon, but if you figure out the cause I'd be happy to take a pull request! |
I also bumped into this problem with prefetch_related as mentioned in #110 (comment) Django version: 1.11.16 Looks like the prefetch cache is not where one would expect it. I suspect that this happens because prefetch_related is handled after the iterator has converted the found instances to the appropriate child classes. Unfortunately I do not have time (or the know-how) to make a PR to fix this. (I was hoping this package would be plug-and-play to save me time. ;-) ) So for now I'm going with the weird but working fix of using the extra classname when looking up the prefetched objects. I just wanted to make it known that the bug still exists and what might be causing it. |
I've bumped into this as well. From what I can see, this is hard to fix. As workaround, you could override |
Consider having the following example models:
When I attempt to select all posts and prefetch PhotoPost's photos:
The following error is raised:
Is prefetch_related supported in combination with select_sublcasses?
Note that I have tested this on Django 1.5 and 1.6 with the latest release of django-model-utils.
Disclaimer: the given example is reworked version of the following one: http://stackoverflow.com/questions/19511368/prefetch-related-with-django-1-5-django-model-utils
The text was updated successfully, but these errors were encountered: