﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7315	Forcing Inner join to a nullable foreignkey when it is inherited from an abstract class	Marinho Brandão	nobody	"I am having a similar problem to #6981 ticket, but in my case the queryset doesn't uses select_related, and the column is in the inherited abstract class.

models.py:

{{{
class AbstractCrane(models.Model):
    manufacturer = models.ForeignKey(
            'Company',
            null=True,
            blank=True,
            db_column='new_manufacturer_id',
            limit_choices_to={'is_manufacturer': True},
            )

class WishListCrane(AbstractCrane):
    pass
}}}

queryset (there is 1 row, but it doesn't is found):

{{{
>>> WishListCrane.objects.all()
[]

>>> connection.queries[-1]['sql']
u'SELECT ""cranes_wishlistcrane"".""id"", ""cranes_wishlistcrane"".""new_manufacturer_id"", ""cranes_wishlistcrane"".""other_manufacturer"", ""cranes_wishlistcrane"".""category_id"", ""cranes_wishlistcrane"".""other_category"", ""cranes_wishlistcrane"".""model"", ""cranes_wishlistcrane"".""lift_capacity"", ""cranes_wishlistcrane"".""boom_length"", ""cranes_wishlistcrane"".""jib_length"", ""cranes_wishlistcrane"".""description"", ""cranes_wishlistcrane"".""user_id"", ""cranes_wishlistcrane"".""require_manufacturer"", ""cranes_wishlistcrane"".""require_categories"", ""cranes_wishlistcrane"".""require_model"", ""cranes_wishlistcrane"".""require_lift_capacity"", ""cranes_wishlistcrane"".""require_boom_length"", ""cranes_wishlistcrane"".""require_jib_length"", ""cranes_wishlistcrane"".""require_description"" FROM ""cranes_wishlistcrane"" INNER JOIN ""companies_company"" ON (""cranes_wishlistcrane"".""new_manufacturer_id"" = ""companies_company"".""id"") ORDER BY ""companies_company"".""name"" ASC, ""cranes_wishlistcrane"".""model"" ASC'
}}}

I found this part of django/db/models/sql/query.py, and tought maybe it is wrong:

{{{
840:         elif promote or outer_if_first:
841:            join_type = self.LOUTER
}}}

I modified to:

{{{
840:         elif promote or outer_if_first or nullable:
841:            join_type = self.LOUTER
}}}

and worked.

I'm nor sure if this is correct for the architecture, because I had no made a better checking, but worked for me"		closed	Database layer (models, ORM)	dev		fixed	qsrf-cleanup		Unreviewed	1	0	0	0	0	0
