InheritanceManager get_subclass may be clobbering previous select_subclasses #91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is not merge ready, and is a sketch of something I think is an issue.
Basically, given something like:
The expectation I'd have is that
obj
is of whateveronly_one_type
yields down to, even if, say, there'sonly_one_type__subclass
further down the inheritance chain, because that's what was requested.As it stands, the
get_subclass
method on the InheritanceQuerySet does a bareselect_subclasses
assuming that it needs to do so - this also means that given a parent model with a lot of subclasses, it doesLEFT OUTER JOIN
for each one, even if you've asked for only a subset to be joined.The pull request is intended to change that so that the
get_subclass
method inspectsself
for asubclasses
attr, in the same way the iterator itself does.However, the tests as I've committed them are not usefully functional in demonstrating the problem at hand, with the exception of
test_get_subclass_unrelated_instance
- the very nature of the problem (a bareselect_subclasses
replacing any previous) means the others pass, and I can't currently think of a clear and non-convoluted way of inspecting thesubclasses
attr on the queryset, because it's not a queryset we're getting back, but an individual downcast object.As such, I'm opening this PR by way of discussing whether we think it's a problem, and how it can be tested reasonably.