From: Mike Bayer Date: Tue, 17 Dec 2013 00:32:10 +0000 (-0500) Subject: - for [ticket:2651], leaving CheckConstraint alone, preferring to keep X-Git-Tag: rel_0_9_0~27^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=207aaf2f41cff5970b34999d3cfc845a3b0df29c;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - for [ticket:2651], leaving CheckConstraint alone, preferring to keep backwards compatibility. A note about backslashing escapes is added. Because the Text() construct now supports bind params better, the example given in the code raises an exception now, so that should cover us. The exception itself has been enhanced to include the key name of the bound param. We're backporting this to 0.8 but 0.8 doesn't have the text->bind behavior that raises. --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index f137aebb7b..3460e5c685 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -11,6 +11,14 @@ .. changelog:: :version: 0.8.5 + .. change:: + :tags: enhancement, sql + :versions: 0.9.0b2 + + The exception raised when a :class:`.BindParameter` is present + in a compiled statement without a value now includes the key name + of the bound parameter in the error message. + .. change:: :tags: bug, orm :versions: 0.9.0b2 diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 3c8d71331d..1d38c9ad3c 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -970,8 +970,9 @@ class SQLCompiler(Compiled): (within_columns_clause and \ self.ansi_bind_rules): if bindparam.value is None: - raise exc.CompileError("Bind parameter without a " - "renderable value not allowed here.") + raise exc.CompileError("Bind parameter '%s' without a " + "renderable value not allowed here." + % bindparam.key) return self.render_literal_bindparam(bindparam, within_columns_clause=True, **kwargs) diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 4d9dc2bda7..6205ada34a 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2272,7 +2272,11 @@ class CheckConstraint(Constraint): :param sqltext: A string containing the constraint definition, which will be used - verbatim, or a SQL expression construct. + verbatim, or a SQL expression construct. If given as a string, + the object is converted to a :class:`.Text` object. If the textual + string includes a colon character, escape this using a backslash:: + + CheckConstraint(r"foo ~ E'a(?\:b|c)d") :param name: Optional, the in-database name of the constraint. diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index ca24deb313..a5916c8256 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -1174,8 +1174,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): dialect=dialect ) - assert_raises( + assert_raises_message( exc.CompileError, + "Bind parameter 'foo' without a renderable value not allowed here.", bindparam("foo").in_([]).compile, dialect=dialect )