Michael Bayer wrote:
> Chris Withers wrote:
>> All the tests bar test_mapper_args_composite pass, and that currently
>> blows up with a rather bizarre:
>
> There's a Column there getting sent to the mapper that doesn't yet have a
> key.  It's None, so you get that error.   Declarative sets up those
> keys/names on the columns in the metaclass so somehow this test is messing
> up the order of initialization.  I'll try to have a deeper look.

this fixes it:

class MixinMeta(DeclarativeMeta):
    def __init__(cls, classname, bases, dict_):
        for base in bases:
            names = dir(base)
            if "__mixin__" in names:
                to_mix = []
                column_copies = dict((c, c.copy())
                                for c in
                                [getattr(base, name) for name in names]
                                if isinstance(c, Column)
                               )

                for name in names:
                    obj = getattr(base,name)
                    if isinstance(obj, Column):
                        to_mix.append((name,column_copies[obj]))

                    elif name=='__table_args__' and name not in cls.__dict__:
                        setattr(cls,name,obj)

                    elif name == '__mapper_args__':
                        d = {}
                        for k, v in base.__mapper_args__.iteritems():
                            if v in column_copies:
                                v = column_copies[v]
                            d[k] = v
                        cls.__mapper_args__ = d
                dict_.update(to_mix)

        # work around declarative evilness
        # ..with more evilness :-(
        if '__table_args__' in cls.__dict__:
            cls.__table_args__=cls.__table_args__

        return DeclarativeMeta.__init__(cls, classname, bases, dict_)


the __mapper_args__ behavior still needs to be fixed in core as per #1393
as well, not sure if that changes the requirements for the recipe.



>
>
>
>>
>> Traceback (most recent call last):
>>    File "test_mixable.py", line 177, in test_mapper_args_composite
>>      class MyModel(Base,MyMixin1,MyMixin2):
>>    File "mixable.py", line 27, in __init__
>>      return DeclarativeMeta.__init__(cls, classname, bases, dict_)
>>    File
>> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/ext/declarative.py",
>> line 561, in __init__
>>      _as_declarative(cls, classname, dict_)
>>    File
>> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/ext/declarative.py",
>> line 554, in _as_declarative
>>      cls.__mapper__ = mapper_cls(cls, table, properties=our_stuff,
>> **mapper_args)
>>    File
>> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/orm/__init__.py",
>> line 751, in mapper
>>      return Mapper(class_, local_table, *args, **params)
>>    File
>> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/orm/mapper.py",
>> line 198, in __init__
>>      self._configure_properties()
>>    File
>> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/orm/mapper.py",
>> line 514, in _configure_properties
>>      if self._should_exclude(col.key, col.key, local=False):
>>    File
>> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/orm/mapper.py",
>> line 985, in _should_exclude
>>      if getattr(self.class_, assigned_name, None)\
>> TypeError: Error when calling the metaclass bases
>>      getattr(): attribute name must be string
>>
>> Any idea what's causing that? If I move the type_ columns the the
>> __mapper_args__ to MyModel, the tests passes...
>>
>> (also note evilness required because declarative gets __table_args__
>> from dict_ rather than the cls, where it should ;-) )
>>
>> cheers,
>>
>> Chris
>> --
>> You received this message because you are subscribed to the Google
>> Groups
>> "sqlalchemy" group.
>> To post to this group, send email to sqlalch...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> sqlalchemy+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/sqlalchemy?hl=en.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to