Hi,
I'm using SQLAlchemy 0.2.1 with Turbogears,
and I see an error when trying to create an instance
of a mapped object.
Environment is as follows:
sqlalchemy is imported with:
import sqlalchemy.mods.threadlocal
import sqlalchemy
module 'model' defines number of Table's objects and
their mappings, in particular:
node_table = Table( "node", __engine__,
Column( 'node_id', Integer, primary_key=True ),
)
message_table = Table( "message", __engine__,
Column( 'message_id', Integer, primary_key=True ),
Column('text', String(255), nullable=False),
Column('node_id', Integer,
ForeignKey('node.node_id')),
Column('created', DateTime),
)
class Node(object):
pass
class User(object):
def __init__(self, node, email, password):
self.email = email
self.password = password
self.node = node
class Message(object):
def __init__(self, origin, text,
created=datetime.now()):
self.origin = origin
self.text = text
self.created = created
mapper(Node, node_table)
mapper(User, user_table, properties = {
'node' : relation(Node)
}
)
mapper(Message, message_table, properties = {
'origin' : relation(Node, backref='messages')
}
)
When turbogears starts, it imports this module (and
presumably also starts several threads)
I'm trying to create instance of Message from within
of one thread, with:
user = self.user_query.get(1)
Message(origin=user.node, text='abcd')
And I get following exception:
......
File "/home/anton/culture/culture/controllers.py",
line 91, in submit
Message(origin=user.node, text=body)
File
"build/bdist.linux-i686/egg/sqlalchemy/orm/mapper.py",
line 398, in init
File "/home/anton/culture/culture/model.py", line
70, in __init__
self.origin = origin
File
"build/bdist.linux-i686/egg/sqlalchemy/attributes.py",
line 56, in __set__
File
"build/bdist.linux-i686/egg/sqlalchemy/attributes.py",
line 373, in set_attribute
File
"build/bdist.linux-i686/egg/sqlalchemy/attributes.py",
line 140, in setattr
File
"build/bdist.linux-i686/egg/sqlalchemy/attributes.py",
line 322, in set
File
"build/bdist.linux-i686/egg/sqlalchemy/orm/unitofwork.py",
line 57, in append
File
"build/bdist.linux-i686/egg/sqlalchemy/util.py", line
387, in append
File
"build/bdist.linux-i686/egg/sqlalchemy/util.py", line
295, in __setrecord
File
"build/bdist.linux-i686/egg/sqlalchemy/attributes.py",
line 217, in do_value_appended
File
"build/bdist.linux-i686/egg/sqlalchemy/attributes.py",
line 92, in value_changed
File
"build/bdist.linux-i686/egg/sqlalchemy/orm/unitofwork.py",
line 52, in do_value_changed
File
"build/bdist.linux-i686/egg/sqlalchemy/orm/session.py",
line 300, in save_or_update
File
"build/bdist.linux-i686/egg/sqlalchemy/orm/session.py",
line 339, in _save_impl
File
"build/bdist.linux-i686/egg/sqlalchemy/orm/session.py",
line 357, in _register_new
File
"build/bdist.linux-i686/egg/sqlalchemy/orm/session.py",
line 374, in _attach
InvalidRequestError: Object '<culture.model.Message
object at 0x4765490c>' is already attached to session
'1197808844' (this is '1082348588')
However I'm able to create instance of Message in
similar way, when not using threads.
Please advise if I'm doing something wrong here,
as I'm new to SQLAlchemy.
Regards,
Anton Krasovsky
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and
Risk!
Fully trained technicians. The highest number of Red Hat
certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?
cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users