]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Change visit name for ColumnElement
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 6 Dec 2017 19:12:42 +0000 (14:12 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 6 Dec 2017 21:06:52 +0000 (16:06 -0500)
No SQLA built-in subclasses ColumnElement without specifying
an alternate visit_name, and user defined ColumnElement
subclasses should avoid being treated like ColumnClause,
e.g. where a Table is present.

Fixes: #4142
Change-Id: I15ed09ba8bdebae4cb0c7e5e5df3f59351477577

doc/build/changelog/unreleased_12/4142.rst [new file with mode: 0644]
lib/sqlalchemy/sql/elements.py
test/sql/test_utils.py

diff --git a/doc/build/changelog/unreleased_12/4142.rst b/doc/build/changelog/unreleased_12/4142.rst
new file mode 100644 (file)
index 0000000..be5ac2f
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, sql
+    :tickets: 4142
+
+    Changed the "visit name" of :class:`.ColumnElement` from "column" to
+    "column_element", so that when this element is used as the basis for a
+    user-defined SQL element, it is not assumed to behave like a table-bound
+    :class:`.ColumnClause` when processed by various SQL traversal utilities,
+    as are commonly used by the ORM.
index 3b2bcb4ff1cea277e7626b057b3983e5e5730b5d..2cc1d9c42382939a17bcc8beb457b4a1c78c5b6d 100644 (file)
@@ -571,7 +571,7 @@ class ColumnElement(operators.ColumnOperators, ClauseElement):
 
     """
 
-    __visit_name__ = 'column'
+    __visit_name__ = 'column_element'
     primary_key = False
     foreign_keys = []
 
index 84e7ad7328b7fcd2dcef88a0ad03a12ae284698f..bd8368cd25b6c190ceeafbfefdbf5d4a21922a10 100644 (file)
@@ -1,8 +1,9 @@
-from sqlalchemy.testing import fixtures, is_true, is_false
+from sqlalchemy.testing import fixtures, is_true, is_false, eq_
 from sqlalchemy import MetaData, Table, Column, Integer, String
 from sqlalchemy import and_, or_, bindparam
-from sqlalchemy.sql.elements import ClauseList
+from sqlalchemy.sql.elements import ClauseList, ColumnElement
 from sqlalchemy.sql import operators
+from sqlalchemy.sql import util as sql_util
 
 
 class CompareClausesTest(fixtures.TestBase):
@@ -106,3 +107,14 @@ class CompareClausesTest(fixtures.TestBase):
         is_false(b1.compare(b8))
         is_false(b8.compare(b9))
         is_true(b8.compare(b8))
+
+
+class MiscTest(fixtures.TestBase):
+    def test_column_element_no_visit(self):
+        class MyElement(ColumnElement):
+            pass
+
+        eq_(
+            sql_util.find_tables(MyElement(), check_columns=True),
+            []
+        )