All,

I am working on a little bit of code that is using ActiveMapper, and
I encountered a problem.  Using the following contrived example:

######################### BEGIN CODE #################################

    from sqlalchemy.ext.activemapper import (ActiveMapper, column,
                                             one_to_many, one_to_one,
                                             objectstore)
    from sqlalchemy import ForeignKey, String, Integer
    import sqlalchemy.ext.activemapper as activemapper

    class Person(ActiveMapper):
        class mapping:
            personIdentifier = column(Integer, primary_key=True)
            personName       = column(String)
            cars             = one_to_many('Car',
                                           colname='personIdentifier',
                                           backref='person')

    class Dealership(ActiveMapper):
        class mapping:
            dealershipIdentifier = column(Integer, primary_key=True)
            dealershipName       = column(String)

    class Car(ActiveMapper):
        class mapping:
            carIdentifier        = column(Integer, primary_key=True)
            carName              = column(String)
            personIdentifier     = column(Integer,
                                     foreign_key=ForeignKey(
                                      'person.personIdentifier'
                                     )
                                   )
            dealershipIdentifier = column(Integer,
                                     foreign_key=ForeignKey(
                                      'dealership.dealershipIdentifier'
                                     )
                                   )
            dealership           = one_to_one('Dealership',
                                       colname='dealershipIdentifier'
                                   )

########################### END CODE #################################

I am able to produce the following stack trace just by importing the
module (meaning, it happens as a result of the metaclass stuff in
ActiveMapper).

######################## BEGIN TRACE #################################

Traceback (most recent call last):
File "attribute_test.py", line 19, in ?
   class Car(ActiveMapper):
File "/lib/sqlalchemy/ext/activemapper.py", line 161, in __init__
   process_relationships(cls)
File "/lib/sqlalchemy/ext/activemapper.py", line 99,  
process_relationships
   class_mapper(klass).add_properties(relations)
File "sqlalchemy/orm/mapper.py", line 310, in add_properties
File "sqlalchemy/orm/mapper.py", line 357, in add_property
File "sqlalchemy/orm/mapper.py", line 966, in init
File "sqlalchemy/orm/properties.py", line 246, in do_init
File "sqlalchemy/orm/properties.py", line 683, in compile
File "sqlalchemy/orm/mapper.py", line 357, in add_property
File "sqlalchemy/orm/mapper.py", line 966, in init
File "sqlalchemy/orm/properties.py", line 243, in do_init
File "sqlalchemy/orm/properties.py", line 347, in _set_class_attribute
File "sqlalchemy/orm/properties.py", line 253, in _register_attribute
File "/lib/sqlalchemy/attributes.py", line 528, in register_attribute
   typecallable = getattr(class_, key, None)
TypeError: Error when calling the metaclass bases
   getattr(): attribute name must be string

########################## END TRACE #################################

I am able to fix this by just adding the following line to the top of
the register_attribute method in `sqlalchemy/attributes.py`:

     if key is None: return

I am not sure why `None` is getting passed into this method as the key
in the first place, but it seems to fix the problem.  Is this a safe
change to put into SQLAlchemy proper, or am I just bandaging the
actual problem?

Thanks!

--
Jonathan LaCour
http://cleverdevil.org


_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to