diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-01-13 15:45:59 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-01-13 15:45:59 +0000 |
| commit | 3e3f309cf99b0123be4e7295891e5531b137e1fb (patch) | |
| tree | f80543a47b33c12839cc041ed17e98915175532b | |
| parent | b99bdc7cee1080e6fd86451c5def2410a697c0b9 (diff) | |
| download | sqlalchemy-3e3f309cf99b0123be4e7295891e5531b137e1fb.tar.gz | |
- It's an error to add new Column objects to a declarative class
that specified an existing table using __table__.
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/ext/declarative.py | 6 | ||||
| -rw-r--r-- | test/ext/declarative.py | 8 |
3 files changed, 15 insertions, 2 deletions
@@ -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 diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 70f50622d..cf47279e8 100644 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -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): diff --git a/test/ext/declarative.py b/test/ext/declarative.py index 71505e48f..c9477b5d8 100644 --- a/test/ext/declarative.py +++ b/test/ext/declarative.py @@ -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 |
