The SQL you've posted certainly looks wrong and I thought I'd spent
enough hours making sure we never constructed something like that. So
there's some edge-case you're hitting that isn't being catered for. No
big deal; we can fix that. However, the model fragments you've posted
don't support the SQL that's being generated. Thus, some of the stuff
you've trimmed is likely to be relevant. Filtering a
"software_installation" model on the "software" field isn't going to
involve selections on the license_key table at all.
Please open a ticket for this and assign it to me (mtredinnick in Trac),
since these tend to be the bugs that I get to fix. However, first,
pleaes create a small, complete example that demonstrates the problem in
a repeatable fashion. Simplest way to do that is to take your existing
models and start removing as many fields as possible until the problem
goes away. You can view the SQL that Django will generate by looking at
qs.query.as_sql()
where "qs" is any queryset (such as
software_installation.objects.filter(...)). You can't do this with
something that returns an immediate result (such as .count()), but
that's because count() doesn't return a queryset; it returns an integer.
The fragment you've posted above doesn't meet the "complete" definition,
since (a) it doesn't have anything for the "software" model, although
that's referred to and (b) if I was to create an empty software model
and run the query, license_key wouldn't show up in the query.
Regards,
Malcolm