From: Mike Bayer Date: Thu, 28 May 2009 00:39:12 +0000 (+0000) Subject: merged -r5974:5987 of trunk X-Git-Tag: rel_0_6_6~205 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c2ae7fbed87c0fe544f3f88b16fe0da350c39d4;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git merged -r5974:5987 of trunk --- diff --git a/CHANGES b/CHANGES index a2ba1c5720..4f47bfe09f 100644 --- a/CHANGES +++ b/CHANGES @@ -4,13 +4,29 @@ CHANGES ======= +0.5.4p3 +======= +- orm + - Fixed bug introduced in 0.5.4 whereby Composite types + fail when default-holding columns are flushed. + 0.5.4p2 ======= - sql - Repaired the printing of SQL exceptions which are not - based on parameters. - + based on parameters or are not executemany() style. + +- 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/exc.py b/lib/sqlalchemy/exc.py index f72bec6fdb..f1678743d9 100644 --- a/lib/sqlalchemy/exc.py +++ b/lib/sqlalchemy/exc.py @@ -132,11 +132,11 @@ class DBAPIError(SQLAlchemyError): self.connection_invalidated = connection_invalidated def __str__(self): - if self.params and len(self.params) > 10: + if isinstance(self.params, (list, tuple)) and len(self.params) > 10 and isinstance(self.params[0], (list, dict, tuple)): return ' '.join((SQLAlchemyError.__str__(self), repr(self.statement), repr(self.params[:2]), - '... and a total of %i bound parameters' % len(self.params))) + '... and a total of %i bound parameter sets' % len(self.params))) return ' '.join((SQLAlchemyError.__str__(self), repr(self.statement), repr(self.params))) diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 5605cdcd1e..2fa2cbd864 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -171,7 +171,7 @@ class CompositeProperty(ColumnProperty): obj = state.get_impl(self.key).get(state, state.dict) if obj is None: obj = self.composite_class(*[None for c in self.columns]) - state.get_impl(self.key).set(state, obj, None) + state.get_impl(self.key).set(state, state.dict, obj, None) if hasattr(obj, '__set_composite_values__'): values = list(obj.__composite_values__()) diff --git a/test/base/except.py b/test/base/except.py index eddd9221e2..37558e3359 100644 --- a/test/base/except.py +++ b/test/base/except.py @@ -29,7 +29,53 @@ 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_tostring_large_dict(self): + try: + raise sa_exceptions.DBAPIError.instance( + 'this is a message', {'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 'f':6, 'g':7, 'h':8, 'i':9, 'j':10, 'k':11}, OperationalError()) + except sa_exceptions.DBAPIError, exc: + assert str(exc).startswith("(OperationalError) 'this is a message' {") + def test_tostring_large_list(self): + try: + raise sa_exceptions.DBAPIError.instance( + 'this is a message', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], OperationalError()) + except sa_exceptions.DBAPIError, exc: + assert str(exc).startswith("(OperationalError) 'this is a message' [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]") + + def test_tostring_large_executemany(self): + try: + raise sa_exceptions.DBAPIError.instance( + 'this is a message', [{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},], OperationalError()) + except sa_exceptions.DBAPIError, exc: + assert str(exc) == "(OperationalError) 'this is a message' [{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}]", str(exc) + + try: + raise sa_exceptions.DBAPIError.instance( + 'this is a message', [{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},], OperationalError()) + except sa_exceptions.DBAPIError, exc: + assert str(exc) == "(OperationalError) 'this is a message' [{1: 1}, {1: 1}] ... and a total of 11 bound parameter sets" + + try: + raise sa_exceptions.DBAPIError.instance( + 'this is a message', [(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)], OperationalError()) + except sa_exceptions.DBAPIError, exc: + assert str(exc) == "(OperationalError) 'this is a message' [(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)]" + + try: + raise sa_exceptions.DBAPIError.instance( + 'this is a message', [(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), ], OperationalError()) + except sa_exceptions.DBAPIError, exc: + assert str(exc) == "(OperationalError) 'this is a message' [(1,), (1,)] ... and a total of 11 bound parameter sets" + def test_db_error_busted_dbapi(self): try: raise sa_exceptions.DBAPIError.instance( diff --git a/test/orm/mapper.py b/test/orm/mapper.py index 26a76301f2..ee3a8b6f06 100644 --- a/test/orm/mapper.py +++ b/test/orm/mapper.py @@ -1918,6 +1918,13 @@ class CompositeTypesTest(_base.MappedTest): sess.flush() assert f1.foob == FBComposite(2, 5, 15, None) + + + f2 = Foobar() + sess.add(f2) + sess.flush() + assert f2.foob == FBComposite(2, None, 15, None) + @testing.resolve_artifact_names def test_set_composite_values(self):