]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- DeclarativeMeta exclusively uses cls.__dict__ (not dict_)
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 Feb 2010 22:31:49 +0000 (22:31 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 Feb 2010 22:31:49 +0000 (22:31 +0000)
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.

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

diff --git a/CHANGES b/CHANGES
index 986ba6ba4f2f71b4c28297e429a88a8f2b0ea102..0d945b9cbfc774aa7fbe3b91d34c2af8e6e324c8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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.
index 234aac17caed8325a628b12b04f5c9b9abf51085..d5bd2906b125b7364d46c8ee3d5e9581db0defa7 100644 (file)
@@ -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):
index 52cea62c4f232dfff646249b4e3fe4460a976a33..9c60e01f3c5e48797c625a5466fb4b02129aeae5 100644 (file)
@@ -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):