Hi

I'd like to setup a small versioning extension. Thus I set up a
MepperExtension an overwitten the instrument_class method:

class VersionExtension(MapperExtension):
    """
    With this extension it should be possible to load a versioned
entity with:

    >>>
db.session.query(Address).filter_by(valid_at=datetime.date.today()).all()

    Declaring a versioned object is done by calling
versioned_entity(allow_overlap=False) method.
    When passing allow_overlap=True there can be multiple versions of
this entity at the same
    time.
    """

    def instrument_class(self, mapper, clazz):

        mapper.add_property('valid_from',
ColumnProperty(Column('valid_from', DateTime, nullable=False)))
        mapper.add_property('valid_to',
ColumnProperty(Column('valid_to', DateTime, nullable=True)))

        class ValidComparator(PropComparator):
            def __eq__(self, other):
                valid_at = self.__clause_element__()
                clazz = mapper.class_
                return and_(
                        or_(
                            and_(clazz.valid_from<=valid_at,
clazz.valid_to>=valid_at),
                            and_(clazz.valid_from<=valid_at,
clazz.valid_to==None),

                        )
                )

        mapper.add_property('valid_at',
ComparableProperty(ValidComparator))

        return EXT_CONTINUE

The problem is, this fails with the error >> AttributeError: 'Mapper'
object has no attribute 'columns' [1]

Did anyone encounter this problem as well or does anyone know what I'm
doing wrong?

Regards,
Florian

[1]
Traceback (most recent call last):
  File "/Users/fm/dev/wlib/roopio/src/roopio/tests/regressiontests/
test_versioning.py", line 56, in test_versioned
    class Entity(db.Base):
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/
python3.1/site-packages/SQLAlchemy-0.6.5-py3.1.egg/sqlalchemy/ext/
declarative.py", line 1231, in __init__
    _as_declarative(cls, classname, cls.__dict__)
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/
python3.1/site-packages/SQLAlchemy-0.6.5-py3.1.egg/sqlalchemy/ext/
declarative.py", line 1224, in _as_declarative
    **mapper_args)
  File "/Users/fm/dev/wlib/wlib/src/wlib/db/__init__.py", line 35, in
mapper
    return orm.mapper(cls, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/
python3.1/site-packages/SQLAlchemy-0.6.5-py3.1.egg/sqlalchemy/orm/
__init__.py", line 861, in mapper
    return Mapper(class_, local_table, *args, **params)
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/
python3.1/site-packages/SQLAlchemy-0.6.5-py3.1.egg/sqlalchemy/orm/
mapper.py", line 215, in __init__
    self._configure_class_instrumentation()
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/
python3.1/site-packages/SQLAlchemy-0.6.5-py3.1.egg/sqlalchemy/orm/
mapper.py", line 391, in _configure_class_instrumentation
    self.extension.instrument_class(self, self.class_)
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/
python3.1/site-packages/SQLAlchemy-0.6.5-py3.1.egg/sqlalchemy/orm/
util.py", line 241, in _do
    ret = getattr(ext, method)(*args, **kwargs)
  File "/Users/fm/dev/wlib/roopio/src/roopio/tests/regressiontests/
test_versioning.py", line 24, in instrument_class
    mapper.add_property('valid_from',
ColumnProperty(Column('valid_from', DateTime, nullable=False)))
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/
python3.1/site-packages/SQLAlchemy-0.6.5-py3.1.egg/sqlalchemy/orm/
mapper.py", line 857, in add_property
    self._configure_property(key, prop, init=self.compiled)
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/
python3.1/site-packages/SQLAlchemy-0.6.5-py3.1.egg/sqlalchemy/orm/
mapper.py", line 730, in _configure_property
    self.columns[key] = col
AttributeError: 'Mapper' object has no attribute 'columns'

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

Reply via email to