From: Mike Bayer Date: Fri, 19 Jun 2015 16:24:09 +0000 (-0400) Subject: - Fixed 1.0 regression where the enhanced behavior of single-inheritance X-Git-Tag: rel_1_0_6~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f4149766c9355b303b669e0bbe4e635dd291ace;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed 1.0 regression where the enhanced behavior of single-inheritance joins of :ticket:`3222` takes place inappropriately for a JOIN along explicit join criteria with a single-inheritance subclass that does not make use of any discriminator, resulting in an additional "AND NULL" clause. fixes #3462 --- diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index b301111295..a02a13ef90 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -18,6 +18,16 @@ .. changelog:: :version: 1.0.6 + .. change:: + :tags: bug, orm + :tickets: 3462 + + Fixed 1.0 regression where the enhanced behavior of single-inheritance + joins of :ticket:`3222` takes place inappropriately + for a JOIN along explicit join criteria with a single-inheritance + subclass that does not make use of any discriminator, resulting + in an additional "AND NULL" clause. + .. change:: :tags: bug, postgresql :tickets: 3454 diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 823b972393..66cb2a3198 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -839,9 +839,10 @@ class _ORMJoin(expression.Join): # or implicit ON clause, augment it the same way we'd augment the # WHERE. single_crit = right_info.mapper._single_table_criterion - if right_info.is_aliased_class: - single_crit = right_info._adapter.traverse(single_crit) - self.onclause = self.onclause & single_crit + if single_crit is not None: + if right_info.is_aliased_class: + single_crit = right_info._adapter.traverse(single_crit) + self.onclause = self.onclause & single_crit def _splice_into_center(self, other): """Splice a join into the center. diff --git a/test/orm/inheritance/test_single.py b/test/orm/inheritance/test_single.py index dbbe4c4354..9f5d21a430 100644 --- a/test/orm/inheritance/test_single.py +++ b/test/orm/inheritance/test_single.py @@ -410,6 +410,31 @@ class RelationshipToSingleTest(testing.AssertsCompiledSQL, fixtures.MappedTest): "AND employees_1.type IN (:type_1)" ) + def test_join_explicit_onclause_no_discriminator(self): + # test issue #3462 + Company, Employee, Engineer = ( + self.classes.Company, + self.classes.Employee, + self.classes.Engineer) + companies, employees = self.tables.companies, self.tables.employees + + mapper(Company, companies, properties={ + 'employees': relationship(Employee) + }) + mapper(Employee, employees) + mapper(Engineer, inherits=Employee) + + sess = create_session() + self.assert_compile( + sess.query(Company, Engineer.name).join( + Engineer, Company.company_id == Engineer.company_id), + "SELECT companies.company_id AS companies_company_id, " + "companies.name AS companies_name, " + "employees.name AS employees_name " + "FROM companies JOIN " + "employees ON companies.company_id = employees.company_id" + ) + def test_outer_join_prop(self): Company, Employee, Engineer = self.classes.Company,\ self.classes.Employee,\