]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed 1.0 regression where the enhanced behavior of single-inheritance
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Jun 2015 16:24:09 +0000 (12:24 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Jun 2015 16:24:09 +0000 (12:24 -0400)
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

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/orm/util.py
test/orm/inheritance/test_single.py

index b301111295c8641bf1bd00b15e75b9315b912c60..a02a13ef9078cd5d4c547297ec32f241057c1f89 100644 (file)
 .. 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
index 823b9723939f70f0b745a98c5a603b03f2392f4f..66cb2a3198854d36d7668ea4e26d387d7b2616d7 100644 (file)
@@ -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.
index dbbe4c4354a303b408632a60027e2b6ca1c2d973..9f5d21a430c0ffe28e5d83a5f32721a6af7a2e45 100644 (file)
@@ -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,\