]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug in Table and Column whereby passing empty
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 25 Jul 2009 21:40:27 +0000 (21:40 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 25 Jul 2009 21:40:27 +0000 (21:40 +0000)
dict for "info" argument would raise an exception.
[ticket:1482]

CHANGES
lib/sqlalchemy/schema.py
test/engine/test_metadata.py

diff --git a/CHANGES b/CHANGES
index 38bdb15b8a9b76d21989b63c61b6eb98a8cb49c2..4ab2422fc15a916c81e2adb848d9eb4dc46cce51 100644 (file)
--- 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
index 5d31543d83345f2106e49033a04f380f51a2d0eb..e641f119b349b1cf30f52cb9603f3bbab8b637aa 100644 (file)
@@ -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()))
index 024d1b854f88bdd84c1ebaa9ec151e4e3a0544bc..ca4fbaa48a525087666d4a442ede79e6de397c58 100644 (file)
@@ -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'
+