summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/roles.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-05-18 20:35:01 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-05-27 21:19:06 -0400
commit47552aa93bedcce3756dc89774f02db9f1868e68 (patch)
tree4a00be1f85b5964e8cf6d035ed94345eba0459e4 /lib/sqlalchemy/sql/roles.py
parent8b2eb2a2d0f4c7e283d96cf3e5263b5dd48e3b14 (diff)
downloadsqlalchemy-47552aa93bedcce3756dc89774f02db9f1868e68.tar.gz
Use roles for ORM alias() conversion
as SELECT statements will have subquery() and not alias(), start getting ready for the places where the ORM coerces SELECTs into subqueries and be ready to warn about it Change-Id: I90d4b6cae2c72816c6b192016ce074589caf4731
Diffstat (limited to 'lib/sqlalchemy/sql/roles.py')
-rw-r--r--lib/sqlalchemy/sql/roles.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/roles.py b/lib/sqlalchemy/sql/roles.py
index 2d3aaf903..053bd7146 100644
--- a/lib/sqlalchemy/sql/roles.py
+++ b/lib/sqlalchemy/sql/roles.py
@@ -100,6 +100,30 @@ class FromClauseRole(ColumnsClauseRole):
raise NotImplementedError()
+class StrictFromClauseRole(FromClauseRole):
+ # does not allow text() or select() objects
+ pass
+
+
+class AnonymizedFromClauseRole(StrictFromClauseRole):
+ # calls .alias() as a post processor
+
+ def _anonymous_fromclause(self, name=None, flat=False):
+ """A synonym for ``.alias()`` that is only present on objects of this
+ role.
+
+ This is an implicit assurance of the target object being part of the
+ role where anonymous aliasing without any warnings is allowed,
+ as opposed to other kinds of SELECT objects that may or may not have
+ an ``.alias()`` method.
+
+ The method is used by the ORM but is currently semi-private to
+ preserve forwards-compatibility.
+
+ """
+ return self.alias(name=name, flat=flat)
+
+
class CoerceTextStatementRole(SQLRole):
_role_name = "Executable SQL, text() construct, or string statement"