summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2017-04-04 10:22:32 -0400
committerGerrit Code Review <gerrit@awstats.zzzcomputing.com>2017-04-04 10:22:32 -0400
commitb4686a0f7864715fdce7c781bafc29da2e91073b (patch)
tree2d1c1eeaf6b594399630030e81cf8513b0df49de
parente28c3c7ec0d74cb0c5cc444cec999a7515656869 (diff)
parent4a4b17e0d3a154094858e73ed1e32c5733047de8 (diff)
downloadsqlalchemy-b4686a0f7864715fdce7c781bafc29da2e91073b.tar.gz
Merge "Apply SQL compilation to sqltext for column-level CHECK constraint"
-rw-r--r--doc/build/changelog/changelog_12.rst12
-rw-r--r--lib/sqlalchemy/sql/compiler.py4
-rw-r--r--test/sql/test_constraints.py13
3 files changed, 28 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_12.rst b/doc/build/changelog/changelog_12.rst
index 1d66adc8e..ad9e73160 100644
--- a/doc/build/changelog/changelog_12.rst
+++ b/doc/build/changelog/changelog_12.rst
@@ -13,6 +13,18 @@
.. changelog::
:version: 1.2.0b1
+ .. change:: 3957
+ :tags: bug, sql
+ :tickets: 3957
+
+ Fixed bug where a column-level :class:`.CheckConstraint` would fail
+ to compile the SQL expression using the underlying dialect compiler
+ as well as apply proper flags to generate literal values as
+ inline, in the case that the sqltext is a Core expression and
+ not just a plain string. This was long-ago fixed for table-level
+ check constraints in 0.9 as part of :ticket:`2742`, which more commonly
+ feature Core SQL expressions as opposed to plain string expressions.
+
.. change:: 3923
:tags: bug, sql
:tickets: 3923
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 441502898..b18f90312 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -2602,7 +2602,9 @@ class DDLCompiler(Compiled):
formatted_name = self.preparer.format_constraint(constraint)
if formatted_name is not None:
text += "CONSTRAINT %s " % formatted_name
- text += "CHECK (%s)" % constraint.sqltext
+ text += "CHECK (%s)" % self.sql_compiler.process(constraint.sqltext,
+ include_table=False,
+ literal_binds=True)
text += self.define_constraint_deferrability(constraint)
return text
diff --git a/test/sql/test_constraints.py b/test/sql/test_constraints.py
index aebbb4c30..3365b3cf0 100644
--- a/test/sql/test_constraints.py
+++ b/test/sql/test_constraints.py
@@ -1137,6 +1137,19 @@ class ConstraintCompilationTest(fixtures.TestBase, AssertsCompiledSQL):
"ALTER TABLE tbl ADD CHECK (a > 5)"
)
+ def test_render_check_constraint_inline_sql_literal(self):
+ t, t2 = self._constraint_create_fixture()
+
+ m = MetaData()
+ t = Table(
+ 't', m,
+ Column('a', Integer, CheckConstraint(Column('a', Integer) > 5)))
+
+ self.assert_compile(
+ schema.CreateColumn(t.c.a),
+ "a INTEGER CHECK (a > 5)"
+ )
+
def test_render_index_sql_literal(self):
t, t2 = self._constraint_create_fixture()