well theres session identifiers that will be stuck on the object if
you dont expunge it, then when you go to put it into another session
it should raise an error.

Strangely enough, I don't get those errors. I'll see what the deal is there, but more important is the test transcript I've pasted below.


what is cache(u) doing exactly ?  just saying expunge(x) then update
(x) shouldnt be raising any errors. 

def cache(u):
    memcache.set(make_key(u), u)

Also, given the earlier setup.py (I'll attach it so we're still on the same page) Here is a test transcript:

>>> from setup import *
>>> u = session.get(User, 1)
[2006-07-10 15:07:53,763] [engine]: SELECT users.email AS users_email, users.id
AS users_id, users.name AS users_name
FROM users
WHERE users.id = ? ORDER BY users.oid
[2006-07-10 15:07:53,763] [engine]: [1]
>>> session.identity_map.keys()
[(<class 'setup.User'>, (1,), None)]
>>> session.expunge(u)
>>> session.identity_map.keys()
[]
>>> session.save_or_update(u)
>>> session.identity_map.keys()
[]
>>> u.email = '[EMAIL PROTECTED]'
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "c:\python\lib\site-packages\sqlalchemy-0.2.4-py2.4.egg\sqlalchemy\attrib
utes.py", line 23, in __set__
    self.set(None, obj, value)
  File "c:\python\lib\site-packages\sqlalchemy-0.2.4-py2.4.egg\sqlalchemy\attrib
utes.py", line 180, in set
    ext.set(event or self, obj, value, old)
  File "c:\python\lib\site-packages\sqlalchemy-0.2.4-py2.4.egg\sqlalchemy\orm\un
itofwork.py", line 55, in set
    sess._register_changed(obj)
  File "build\bdist.win32\egg\sqlalchemy\orm\session.py", line 349, in _register
_changed
  File "build\bdist.win32\egg\sqlalchemy\orm\session.py", line 357, in _register
_dirty
  File "c:\python\lib\site-packages\sqlalchemy-0.2.4-py2.4.egg\sqlalchemy\orm\un
itofwork.py", line 184, in register_dirty
    self._validate_obj(obj)
  File "c:\python\lib\site-packages\sqlalchemy-0.2.4-py2.4.egg\sqlalchemy\orm\un
itofwork.py", line 146, in _validate_obj
    raise InvalidRequestError("Detected a mapped object not present in the curre
nt thread's Identity Map: '%s'.  Use objectstore.import_instance() to place dese
rialized instances or instances from other threads" % repr(obj._instance_key))
sqlalchemy.exceptions.InvalidRequestError: Detected a mapped object not present
in the current thread's Identity Map: '(<class 'setup.User'>, (1,), None)'.  Use
 objectstore.import_instance() to place deserialized instances or instances from
 other threads



Its not that it raises an error when i call session.save_or_update, its that it raises an error when I try to do anything with the object's attributes.

-Michael
import sqlalchemy as sa

__all__ = [ 'session', 'User' ]

class User(object): pass
metadata = sa.BoundMetaData('sqlite:///test.db')
metadata.engine.echo = True
users = sa.Table('users', metadata,
    sa.Column('id', sa.Integer, primary_key=True),
    sa.Column('name', sa.String),
    sa.Column('email', sa.String))
    
User.mapper = sa.mapper(User, users)
User.mapper.compile()

session = sa.create_session()

if __name__ == "__main__":
    metadata.engine.echo = True
    users.create()

    
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to