Skip to content

Commit

Permalink
dont stringify uq deferrable
Browse files Browse the repository at this point in the history
Fixed autogenerate rendering bug where the ``deferrable`` element of
``UniqueConstraint``, a bool, were being stringified rather than repr'ed
when generating Python code.

Fixes: #1613
Change-Id: I24bf7f3542566994559144c08cde2766d9ff4fe1
  • Loading branch information
zzzeek committed Feb 26, 2025
1 parent 4ecf4ad commit 36231bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions alembic/autogenerate/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,9 @@ def _uq_constraint(
has_batch = autogen_context._has_batch

if constraint.deferrable:
opts.append(("deferrable", str(constraint.deferrable)))
opts.append(("deferrable", constraint.deferrable))
if constraint.initially:
opts.append(("initially", str(constraint.initially)))
opts.append(("initially", constraint.initially))
if not has_batch and alter and constraint.table.schema:
opts.append(("schema", _ident(constraint.table.schema)))
if not alter and constraint.name:
Expand Down
7 changes: 7 additions & 0 deletions docs/build/unreleased/1613.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. change::
:tags: bug, autogenerate
:tickets: 1613

Fixed autogenerate rendering bug where the ``deferrable`` element of
``UniqueConstraint``, a bool, were being stringified rather than repr'ed
when generating Python code.
4 changes: 2 additions & 2 deletions tests/test_autogen_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -2437,11 +2437,11 @@ def test_explicit_unique_constraint(self):
t = Table("t", self.metadata, Column("c", Integer))
eq_ignore_whitespace(
autogenerate.render._render_unique_constraint(
UniqueConstraint(t.c.c, deferrable="XYZ"),
UniqueConstraint(t.c.c, deferrable=True),
self.autogen_context,
None,
),
"sa.UniqueConstraint('c', deferrable='XYZ', "
"sa.UniqueConstraint('c', deferrable=True, "
"name=op.f('uq_ct_t_c'))",
)

Expand Down

0 comments on commit 36231bc

Please sign in to comment.