Fixed 2.0 regression where the :class:`.DDL` construct would no longer
``__repr__()`` due to the removed ``on`` attribute not being accommodated.
Pull request courtesy Iuri de Silvio.
Fixes: #10443
Closes: #10442
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10442
Pull-request-sha:
76f0484091b6a35e5953b8d13f3c66c0b1baa9b0
Change-Id: Id49afd681a04e0f05014105b8f15fdb66e6594a0
--- /dev/null
+.. change::
+ :tags: bug, sql
+ :tickets: 10443
+
+ Fixed 2.0 regression where the :class:`.DDL` construct would no longer
+ ``__repr__()`` due to the removed ``on`` attribute not being accommodated.
+ Pull request courtesy Iuri de Silvio.
self.context = context or {}
def __repr__(self):
+ parts = [repr(self.statement)]
+ if self.context:
+ parts.append(f"context={self.context}")
+
return "<%s@%s; %s>" % (
type(self).__name__,
id(self),
- ", ".join(
- [repr(self.statement)]
- + [
- "%s=%r" % (key, getattr(self, key))
- for key in ("on", "context")
- if getattr(self, key)
- ]
- ),
+ ", ".join(parts),
)
)
._should_execute(tbl, cx)
)
+
+ @testing.variation("include_context", [True, False])
+ def test_repr(self, include_context):
+ sql = "SELECT :foo"
+
+ if include_context:
+ context = {"foo": 1}
+ ddl = DDL(sql, context=context)
+ eq_(repr(ddl), f"<DDL@{id(ddl)}; '{sql}', context={context}>")
+ else:
+ ddl = DDL(sql)
+ eq_(repr(ddl), f"<DDL@{id(ddl)}; '{sql}'>")