From: Mike Bayer Date: Sat, 25 Jul 2009 21:40:27 +0000 (+0000) Subject: - Fixed bug in Table and Column whereby passing empty X-Git-Tag: rel_0_5_6~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05a82671c37b778f091e2a15266a1867428f3fdb;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug in Table and Column whereby passing empty dict for "info" argument would raise an exception. [ticket:1482] --- diff --git a/CHANGES b/CHANGES index 38bdb15b8a..4ab2422fc1 100644 --- a/CHANGES +++ b/CHANGES @@ -45,6 +45,10 @@ CHANGES - Unary expressions such as DISTINCT propagate their type handling to result sets, allowing conversions like unicode and such to take place. [ticket:1420] + + - Fixed bug in Table and Column whereby passing empty + dict for "info" argument would raise an exception. + [ticket:1482] - ext - The collection proxies produced by associationproxy are now diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 5d31543d83..e641f119b3 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -72,14 +72,9 @@ class SchemaItem(visitors.Visitable): m = self.metadata return m and m.bind or None - @property + @util.memoized_property def info(self): - try: - return self._info - except AttributeError: - self._info = {} - return self._info - + return {} def _get_table_key(name, schema): if schema is None: @@ -224,8 +219,8 @@ class Table(SchemaItem, expression.TableClause): self.quote = kwargs.pop('quote', None) self.quote_schema = kwargs.pop('quote_schema', None) - if kwargs.get('info'): - self._info = kwargs.pop('info') + if 'info' in kwargs: + self.info = kwargs.pop('info') self._prefixes = kwargs.pop('prefixes', []) @@ -264,7 +259,7 @@ class Table(SchemaItem, expression.TableClause): setattr(self, key, kwargs.pop(key)) if 'info' in kwargs: - self._info = kwargs.pop('info') + self.info = kwargs.pop('info') self.__extra_kwargs(**kwargs) self.__post_init(*args, **kwargs) @@ -602,8 +597,9 @@ class Column(SchemaItem, expression.ColumnClause): self.foreign_keys = util.OrderedSet() util.set_creation_order(self) - if kwargs.get('info'): - self._info = kwargs.pop('info') + if 'info' in kwargs: + self.info = kwargs.pop('info') + if kwargs: raise exc.ArgumentError( "Unknown arguments passed to Column: " + repr(kwargs.keys())) diff --git a/test/engine/test_metadata.py b/test/engine/test_metadata.py index 024d1b854f..ca4fbaa48a 100644 --- a/test/engine/test_metadata.py +++ b/test/engine/test_metadata.py @@ -161,3 +161,29 @@ class TableOptionsTest(TestBase): table2.create() assert [str(x) for x in self.engine.mock if 'CREATE VIRTUAL TABLE' in str(x)] + def test_table_info(self): + + t1 = Table('foo', self.metadata, info={'x':'y'}) + t2 = Table('bar', self.metadata, info={}) + t3 = Table('bat', self.metadata) + assert t1.info == {'x':'y'} + assert t2.info == {} + assert t3.info == {} + for t in (t1, t2, t3): + t.info['bar'] = 'zip' + assert t.info['bar'] == 'zip' + +class ColumnOptionsTest(TestBase): + def test_column_info(self): + + c1 = Column('foo', info={'x':'y'}) + c2 = Column('bar', info={}) + c3 = Column('bat') + assert c1.info == {'x':'y'} + assert c2.info == {} + assert c3.info == {} + + for c in (c1, c2, c3): + c.info['bar'] = 'zip' + assert c.info['bar'] == 'zip' +