]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Column with no name (as in declarative) won't raise a
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 13 Jan 2009 15:38:38 +0000 (15:38 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 13 Jan 2009 15:38:38 +0000 (15:38 +0000)
NoneType error when it's string output is requsted
(such as in a stack trace).

CHANGES
lib/sqlalchemy/ext/declarative.py
lib/sqlalchemy/schema.py
test/ext/declarative.py

diff --git a/CHANGES b/CHANGES
index 409e25340f8b5928b5337ee8d47f4a8220efe3c6..79040856503ec0938806571774195216dd82279b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -51,6 +51,10 @@ CHANGES
       (i.e. column-based mapped class attributes) as column
       arguments. [ticket:1214]
 
+    - Column with no name (as in declarative) won't raise a 
+      NoneType error when it's string output is requsted
+      (such as in a stack trace).
+      
 - declarative
     - Can now specify Column objects on subclasses which have no
       table of their own (i.e. use single table inheritance).  
index a5cb6e9d2d11fd30ef339516a75773840804d5fb..70f50622d710bfc13809a4012c94a920b066c937 100644 (file)
@@ -737,3 +737,4 @@ def _undefer_column_name(key, column):
         column.key = key
     if column.name is None:
         column.name = key
+    util.reset_memoized(column, 'description')
\ No newline at end of file
index b8a36ebb5a0e74d02752a653db77772d47012d70..792a7e9239c60f7066548ba369befeccd791aba7 100644 (file)
@@ -617,9 +617,16 @@ class Column(SchemaItem, expression.ColumnClause):
         else:
             return self.description
 
+    @util.memoized_property
+    def description(self):
+        if not self.name:
+            return "(no name)"
+        else:
+            return self.name.encode('ascii', 'backslashreplace')
+
+    @property
     def bind(self):
         return self.table.bind
-    bind = property(bind)
 
     def references(self, column):
         """Return True if this Column references the given column via foreign key."""
index 3176832f309fbd65be37676f496751eaa75900e5..71505e48f5cd491897ad21ef9d81cbb8ebdc66b6 100644 (file)
@@ -63,6 +63,18 @@ class DeclarativeTest(DeclarativeTestBase):
             class User(Base):
                 id = Column('id', Integer, primary_key=True)
         self.assertRaisesMessage(sa.exc.InvalidRequestError, "does not have a __table__", go)
+    
+    def test_undefer_column_name(self):
+        # TODO: not sure if there was an explicit
+        # test for this elsewhere
+        foo = Column(Integer)
+        eq_(str(foo), '(no name)')
+        eq_(foo.key, None)
+        eq_(foo.name, None)
+        decl._undefer_column_name('foo', foo)
+        eq_(str(foo), 'foo')
+        eq_(foo.key, 'foo')
+        eq_(foo.name, 'foo')
         
     def test_recompile_on_othermapper(self):
         """declarative version of the same test in mappers.py"""