indeed. fixed this in r6099.
On Jul 8, 2009, at 6:09 PM, Brad Wells wrote:
>
> I receive "AttributeError: '_ProxyImpl' object has no attribute
> 'get_history'" when attempting to use session.is_modified on a class
> with a synonym with a descriptor. Removing the descriptor from the
> synonym prevents the error. Code and full traceback below.
>
> #################################################
> from sqlalchemy import Table, Column, Integer, String, MetaData,
> create_engine, ForeignKey
> from sqlalchemy.orm import relation, sessionmaker, scoped_session,
> mapper, synonym, object_session
> from sqlalchemy.orm.interfaces import MapperExtension
>
>
> class SynonymProp(object):
> def __init__(self, attribute):
> self._attribute = attribute
>
> def __set__(s, obj, value):
> setattr(obj, s._attribute, value)
> def __delete__(s, obj):
> delattr(obj, s._attribute)
> def __get__(s, obj, owner):
> if obj is None:
> return s
> return getattr(obj, s._attribute)
>
> class Extension(MapperExtension):
>
> def before_update(self, mapper, connection, instance):
> object_session(instance).is_modified(instance,
> include_collections=False)
>
>
> engine = create_engine('sqlite:///', echo=False)
>
> Session = scoped_session(sessionmaker(autoflush=True,
> autocommit=False, bind=engine))
> metadata = MetaData()
>
> bananas = Table('bananas', metadata,
> Column('id', Integer, primary_key=True),
> Column('name', String(35)))
>
> class Banana(object): pass
>
> mapper(Banana, bananas, extension=Extension(), properties={
> 'name': synonym('_name', map_column=True, descriptor=SynonymProp
> ('_name'))
> })
>
> metadata.create_all(bind=engine)
>
> b1 = Banana()
> Session.add(b1)
> Session.commit()
>
> b1.name = 'Bob'
>
> Session.commit()
> #################################################
>
>
>
> Traceback (most recent call last):
> File "sa_test.py", line 50, in <module>
> Session.commit()
> File "c:\program files\python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\scoping.py", line 121, in do
> return getattr(self.registry(), name)(*args, **kwargs)
> File "C:\PROGRA~1\Python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\session.py", line 673, in commit
> self.transaction.commit()
> File "C:\PROGRA~1\Python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\session.py", line 378, in commit
> self._prepare_impl()
> File "C:\PROGRA~1\Python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\session.py", line 362, in _prepare_impl
> self.session.flush()
> File "C:\PROGRA~1\Python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\session.py", line 1354, in flush
> self._flush(objects)
> File "C:\PROGRA~1\Python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\session.py", line 1432, in _flush
> flush_context.execute()
> File "c:\program files\python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\unitofwork.py", line 257, in execute
> UOWExecutor().execute(self, tasks)
> File "c:\program files\python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\unitofwork.py", line 720, in execute
> self.execute_save_steps(trans, task)
> File "c:\program files\python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\unitofwork.py", line 735, in
> execute_save_steps
> self.save_objects(trans, task)
> File "c:\program files\python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\unitofwork.py", line 726, in save_objects
> task.mapper._save_obj(task.polymorphic_tosave_objects, trans)
> File "c:\program files\python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\mapper.py", line 1251, in _save_obj
> mapper.extension.before_update(mapper, connection, state.obj())
> File "c:\program files\python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\util.py", line 234, in _do
> ret = getattr(ext, method)(*args, **kwargs)
> File "sa_test.py", line 22, in before_update
> object_session(instance).is_modified(instance,
> include_collections=False)
> File "C:\PROGRA~1\Python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\session.py", line 1483, in is_modified
> (added, unchanged, deleted) = attr.get_history(instance,
> passive=passive)
> File "C:\PROGRA~1\Python\lib\site-packages\sqlalchemy-0.5.4p2-
> py2.5.egg\sqlalchemy\orm\attributes.py", line 108, in get_history
> return self.impl.get_history(instance_state(instance),
> instance_dict(instance), **kwargs)
> AttributeError: '_ProxyImpl' object has no attribute 'get_history'
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---