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_8_5~72 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0fefc6e22641287100eb0648cf1264daeefeb020;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. Conflicts: lib/sqlalchemy/sql/schema.py --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 9e8d2af1d6..4141585e07 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/schema.py b/lib/sqlalchemy/schema.py index d623cf4d9b..4d231d5acb 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -2133,7 +2133,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/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index d537536911..ad92396eef 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -786,8 +786,9 @@ class SQLCompiler(engine.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/test/sql/test_compiler.py b/test/sql/test_compiler.py index f35c6a7f84..b3451b9dfc 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -1304,8 +1304,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 )