From f554209ebd676fd7c30e4c494a42a049d8afd3f0 Mon Sep 17 00:00:00 2001 From: RamonWill Date: Tue, 28 Apr 2020 14:19:06 -0400 Subject: fixes #4212 raise an error if selectable and flat/aliased are sent to with_polymorphic simultaenously Hi, This is a proposed fix for Issue #4212 When the selectable argument is passed to with_polymorphic it is already aliased. Therefore an argument error should be raised if flat is also True. I have added an if statement to the with_polymorphic function, that raises an Argument Error if selectable is none/False AND if flat=True. I have also included a test. ### Checklist This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [X ] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. Kind Regards, Ramon Closes: #5232 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5232 Pull-request-sha: eae20cdadac82ca1e0352000fe0211e20b590e8b Change-Id: I49c3022296608ede43de7f508fa993fa97dda81a --- lib/sqlalchemy/orm/util.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 16aa98adb..28c311450 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -945,6 +945,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) -- cgit v1.2.1