]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
corrections to resolution for issue 4212
authorRamonWill <ramonwilliams@hotmail.co.uk>
Tue, 7 Apr 2020 18:57:40 +0000 (19:57 +0100)
committerRamonWill <ramonwilliams@hotmail.co.uk>
Tue, 7 Apr 2020 18:57:40 +0000 (19:57 +0100)
lib/sqlalchemy/orm/util.py
test/orm/inheritance/test_with_poly.py

index 48e9b19bfe56e4e5424f897972790276852ab53e..388bf76ec70e56e984839c5f0fb54bc88197e833 100644 (file)
@@ -932,6 +932,13 @@ def with_polymorphic(
        only be specified if querying for one specific subtype only
     """
     primary_mapper = _class_to_mapper(base)
+
+    if selectable not in (None, False) and flat:
+        raise sa_exc.ArgumentError(
+            "the 'flat' and 'selectable' arguments cannot be passed "
+            "simultaneously to with_polymorphic()"
+        )
+
     if _existing_alias:
         assert _existing_alias.mapper is primary_mapper
         classes = util.to_set(classes)
index 3ff6c191c4aa4e4396b4936b158db448ccdd8df6..0b0138e213bd27b18e4b8955b72fb7bfd32b3db2 100644 (file)
@@ -1,4 +1,5 @@
 from sqlalchemy import and_
+from sqlalchemy import exc
 from sqlalchemy import or_
 from sqlalchemy import testing
 from sqlalchemy.orm import create_session
@@ -16,6 +17,21 @@ from ._poly_fixtures import Manager
 from ._poly_fixtures import Person
 
 
+class WithPolymorphicAPITest(_Polymorphic, _PolymorphicFixtureBase):
+    def test_no_use_flat_and_aliased(self):
+        sess = create_session()
+
+        subq = sess.query(Person).subquery()
+
+        testing.assert_raises_message(
+            exc.ArgumentError,
+            "the 'flat' and 'selectable' arguments cannot be passed "
+            "simultaneously to with_polymorphic()",
+            with_polymorphic, Person, [Engineer],
+            selectable=subq, flat=True
+        )
+
+
 class _WithPolymorphicBase(_PolymorphicFixtureBase):
     def test_join_base_to_sub(self):
         sess = create_session()