diff options
-rw-r--r-- | CHANGES | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/declarative.py | 15 | ||||
-rw-r--r-- | test/ext/test_declarative.py | 3 |
3 files changed, 18 insertions, 8 deletions
@@ -140,6 +140,14 @@ CHANGES Note that it is *not* built/installed by default. See README for installation instructions. +- declarative + - DeclarativeMeta exclusively uses cls.__dict__ (not dict_) + as the source of class information; _as_declarative exclusively + uses the dict_ passed to it as the source of class information + (which when using DeclarativeMeta is cls.__dict__). This should + in theory make it easier for custom metaclasses to modify + the state passed into _as_declarative. + - mysql - Fixed reflection bug whereby when COLLATE was present, nullable flag and server defaults would not be reflected. diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 234aac17c..d5bd2906b 100644 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -468,11 +468,11 @@ def _as_declarative(cls, classname, dict_): del our_stuff[key] table = None - if '__table__' not in cls.__dict__: - if '__tablename__' in cls.__dict__: + if '__table__' not in dict_: + if '__tablename__' in dict_: tablename = cls.__tablename__ - table_args = cls.__dict__.get('__table_args__') + table_args = dict_.get('__table_args__') if isinstance(table_args, dict): args, table_kw = (), table_args elif isinstance(table_args, tuple): @@ -486,7 +486,7 @@ def _as_declarative(cls, classname, dict_): else: args, table_kw = (), {} - autoload = cls.__dict__.get('__autoload__') + autoload = dict_.get('__autoload__') if autoload: table_kw['autoload'] = True @@ -497,7 +497,8 @@ def _as_declarative(cls, classname, dict_): if cols: for c in cols: if not table.c.contains_column(c): - raise exceptions.ArgumentError("Can't add additional column %r when specifying __table__" % key) + raise exceptions.ArgumentError( + "Can't add additional column %r when specifying __table__" % key) mapper_args = getattr(cls, '__mapper_args__', {}) if 'inherits' not in mapper_args: @@ -557,8 +558,8 @@ class DeclarativeMeta(type): def __init__(cls, classname, bases, dict_): if '_decl_class_registry' in cls.__dict__: return type.__init__(cls, classname, bases, dict_) - - _as_declarative(cls, classname, dict_) + + _as_declarative(cls, classname, cls.__dict__) return type.__init__(cls, classname, bases, dict_) def __setattr__(cls, key, value): diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py index 52cea62c4..9c60e01f3 100644 --- a/test/ext/test_declarative.py +++ b/test/ext/test_declarative.py @@ -280,7 +280,8 @@ class DeclarativeTest(DeclarativeTestBase): # hasattr() on a compile-loaded attribute hasattr(User.addresses, 'property') # the exeption is preserved - assert_raises_message(sa.exc.InvalidRequestError, r"suppressed within a hasattr\(\)", compile_mappers) + assert_raises_message(sa.exc.InvalidRequestError, + r"suppressed within a hasattr\(\)", compile_mappers) def test_custom_base(self): class MyBase(object): |