]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where a fair number of SQL elements within
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 9 Oct 2014 21:20:30 +0000 (17:20 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 9 Oct 2014 21:20:30 +0000 (17:20 -0400)
the sql package would fail to ``__repr__()`` successfully,
due to a missing ``description`` attribute that would then invoke
a recursion overflow when an internal AttributeError would then
re-invoke ``__repr__()``.
fixes #3195

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/sql/elements.py
test/sql/test_selectable.py

index 692c6e392505f419232797d1c5eb0d54da604b3d..e2b893d07fc08b051c4169c78cb5cdd10fb9ad68 100644 (file)
 .. changelog::
     :version: 0.9.8
 
+    .. change::
+        :tags: bug, sql
+        :versions: 1.0.0
+        :tickets: 3195
+
+        Fixed bug where a fair number of SQL elements within
+        the sql package would fail to ``__repr__()`` successfully,
+        due to a missing ``description`` attribute that would then invoke
+        a recursion overflow when an internal AttributeError would then
+        re-invoke ``__repr__()``.
+
     .. change::
         :tags: bug, declarative, orm
         :versions: 1.0.0
index db14031d203cc059ca5c8511dd6dedbbf21fdaa9..c38d831061926dfa526fedba644e2debffaefcbe 100644 (file)
@@ -228,6 +228,7 @@ class ClauseElement(Visitable):
     is_selectable = False
     is_clause_element = True
 
+    description = None
     _order_by_label_element = None
     _is_from_container = False
 
@@ -540,7 +541,7 @@ class ClauseElement(Visitable):
     __nonzero__ = __bool__
 
     def __repr__(self):
-        friendly = getattr(self, 'description', None)
+        friendly = self.description
         if friendly is None:
             return object.__repr__(self)
         else:
index a3b2b0e930d39c9358f2f5642be73fae3d9c0462..99d0cbe766d327d65d72f1aa75292ecc67eda35b 100644 (file)
@@ -5,6 +5,7 @@ from sqlalchemy.testing import eq_, assert_raises, \
 from sqlalchemy import *
 from sqlalchemy.testing import fixtures, AssertsCompiledSQL, \
     AssertsExecutionResults
+from sqlalchemy.sql import elements
 from sqlalchemy import testing
 from sqlalchemy.sql import util as sql_util, visitors, expression
 from sqlalchemy import exc
@@ -1934,6 +1935,29 @@ class AnnotationsTest(fixtures.TestBase):
         assert (c2 == 5).left._annotations == {"foo": "bar", "bat": "hoho"}
 
 
+class ReprTest(fixtures.TestBase):
+    def test_ensure_repr_elements(self):
+        for obj in [
+            elements.Cast(1, 2),
+            elements.TypeClause(String()),
+            elements.ColumnClause('x'),
+            elements.BindParameter('q'),
+            elements.Null(),
+            elements.True_(),
+            elements.False_(),
+            elements.ClauseList(),
+            elements.BooleanClauseList.and_(),
+            elements.Tuple(),
+            elements.Case([]),
+            elements.Extract('foo', column('x')),
+            elements.UnaryExpression(column('x')),
+            elements.Grouping(column('x')),
+            elements.Over(func.foo()),
+            elements.Label('q', column('x')),
+        ]:
+            repr(obj)
+
+
 class WithLabelsTest(fixtures.TestBase):
 
     def _assert_labels_warning(self, s):