From d6b9757778edea97bdbda5c98eb61b37d93296cc Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 26 May 2009 01:00:46 +0000 Subject: [PATCH] - added unit test for exception formatting - Deprecated the hardcoded TIMESTAMP function, which when used as func.TIMESTAMP(value) would render "TIMESTAMP value". This breaks on some platforms as Postgres doesn't allow bind parameters to be used in this context. The hard-coded uppercase is also inappropriate and there's lots of other PG casts that we'd need to support. So instead, use text constructs i.e. select(["timestamp '12/05/09'"]). --- CHANGES | 12 +++++++++++- lib/sqlalchemy/databases/postgres.py | 3 +-- test/base/except.py | 9 ++++++++- test/dialect/postgres.py | 2 ++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index a2ba1c5720..314794b587 100644 --- a/CHANGES +++ b/CHANGES @@ -10,7 +10,17 @@ CHANGES - sql - Repaired the printing of SQL exceptions which are not based on parameters. - + +- postgres + - Deprecated the hardcoded TIMESTAMP function, which when + used as func.TIMESTAMP(value) would render "TIMESTAMP value". + This breaks on some platforms as Postgres doesn't allow + bind parameters to be used in this context. The hard-coded + uppercase is also inappropriate and there's lots of other + PG casts that we'd need to support. So instead, use + text constructs i.e. select(["timestamp '12/05/09'"]). + + 0.5.4p1 ======= diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 068afaf3dd..4fc79921ba 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -706,7 +706,6 @@ class PGDialect(default.DefaultDialect): return domains - class PGCompiler(compiler.DefaultCompiler): operators = compiler.DefaultCompiler.operators.copy() operators.update( @@ -721,7 +720,7 @@ class PGCompiler(compiler.DefaultCompiler): functions = compiler.DefaultCompiler.functions.copy() functions.update ( { - 'TIMESTAMP':lambda x:'TIMESTAMP %s' % x, + 'TIMESTAMP':util.deprecated(message="Use a literal string 'timestamp ' instead")(lambda x:'TIMESTAMP %s' % x), } ) diff --git a/test/base/except.py b/test/base/except.py index 457137c4ce..c2b60f32a7 100644 --- a/test/base/except.py +++ b/test/base/except.py @@ -25,7 +25,14 @@ class WrapTest(unittest.TestCase): '', [], OperationalError()) except sa_exceptions.DBAPIError: self.assert_(True) - + + def test_tostring(self): + try: + raise sa_exceptions.DBAPIError.instance( + 'this is a message', None, OperationalError()) + except sa_exceptions.DBAPIError, exc: + assert str(exc) == "(OperationalError) 'this is a message' None" + def test_db_error_busted_dbapi(self): try: raise sa_exceptions.DBAPIError.instance( diff --git a/test/dialect/postgres.py b/test/dialect/postgres.py index d613ad2ddf..2dfbe018cc 100644 --- a/test/dialect/postgres.py +++ b/test/dialect/postgres.py @@ -865,6 +865,8 @@ class ArrayTest(TestBase, AssertsExecutionResults): class TimeStampTest(TestBase, AssertsExecutionResults): __only_on__ = 'postgres' + + @testing.uses_deprecated() def test_timestamp(self): engine = testing.db connection = engine.connect() -- 2.47.2