]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- It's an error to add new Column objects to a declarative class
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 13 Jan 2009 15:45:59 +0000 (15:45 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 13 Jan 2009 15:45:59 +0000 (15:45 +0000)
that specified an existing table using __table__.

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

diff --git a/CHANGES b/CHANGES
index 79040856503ec0938806571774195216dd82279b..c7846b9c0d916fe52ec893eeeefa17f895275a7d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -73,6 +73,9 @@ CHANGES
       mapping than you'd normally get with explicit `mapper()`
       calls unless you set up the `exclude_properties` arguments
       explicitly.
+
+    - It's an error to add new Column objects to a declarative class
+      that specified an existing table using __table__.
       
 - mysql
     - Added the missing keywords from MySQL 4.1 so they get escaped
index 70f50622d710bfc13809a4012c94a920b066c937..cf47279e8a435089c56097cc389216f20409e73f 100644 (file)
@@ -478,7 +478,9 @@ def _as_declarative(cls, classname, dict_):
                                           *(tuple(cols) + tuple(args)), **table_kw)
     else:
         table = cls.__table__
-
+        if cols:
+            raise exceptions.ArgumentError("Can't add additional columns when specifying __table__")
+            
     mapper_args = getattr(cls, '__mapper_args__', {})
     if 'inherits' not in mapper_args:
         inherits = cls.__mro__[1]
@@ -530,7 +532,7 @@ def _as_declarative(cls, classname, dict_):
             mapper_args['exclude_properties'] = exclude_properties = \
                 set([c.key for c in inherited_table.c if c not in inherited_mapper._columntoproperty])
             exclude_properties.difference_update([c.key for c in cols])
-        
+    
     cls.__mapper__ = mapper_cls(cls, table, properties=our_stuff, **mapper_args)
 
 class DeclarativeMeta(type):
index 71505e48f5cd491897ad21ef9d81cbb8ebdc66b6..c9477b5d85c1e53f51fa6dbb7b1c1dd6b90f2984 100644 (file)
@@ -63,6 +63,14 @@ 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_cant_add_columns(self):
+        t = Table('t', Base.metadata, Column('id', Integer, primary_key=True))
+        def go():
+            class User(Base):
+                __table__ = t
+                foo = Column(Integer, primary_key=True)
+        self.assertRaisesMessage(sa.exc.ArgumentError, "add additional columns", go)
     
     def test_undefer_column_name(self):
         # TODO: not sure if there was an explicit