[sqlalchemy] Sessions and threads, find in one thread, use in another
In my current application I am running a rather expensive query in a background thread, but then I need to use the results in the foreground thread. The object I find has a great deal of lazy evaluated properties that link it to several other mapped objects. As it stands now, the application is only following the lazy properties when it uses the object in the primary thread. The has multiple engines connected to multiple databases. I have a separate session for each database for each thread. (Note: right now I am doing this manually but I am debating whether I should be using something like SessionContext.) What I am worried about is that by querying the initial parent object in the background thread and then using it's lazy props in the foreground thread, I think SA is probably using the background session to evaluate these links. Is there a recommended way to deal with a situation like this? In other words, what is the recommended practice for moving, reusing objects from a session across multiple threads. Is there some way to remap the object and attach it to the foreground session? -Allen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Sessions and threads, find in one thread, use in another
On Dec 13, 2007, at 9:55 AM, Allen Bierbaum wrote: In my current application I am running a rather expensive query in a background thread, but then I need to use the results in the foreground thread. The object I find has a great deal of lazy evaluated properties that link it to several other mapped objects. As it stands now, the application is only following the lazy properties when it uses the object in the primary thread. The has multiple engines connected to multiple databases. I have a separate session for each database for each thread. (Note: right now I am doing this manually but I am debating whether I should be using something like SessionContext.) What I am worried about is that by querying the initial parent object in the background thread and then using it's lazy props in the foreground thread, I think SA is probably using the background session to evaluate these links. Is there a recommended way to deal with a situation like this? In other words, what is the recommended practice for moving, reusing objects from a session across multiple threads. Is there some way to remap the object and attach it to the foreground session? theres two general options here. the most appropriate way to move the object between sessions is to use session.merge(). this will create a copy of the object in the target session, which is returned, leaving the old one unchanged, so that it can additionally be merged elsewhere. as of version 0.4.1 we added a flag to merge called dont_load which prevents merge() from reloading the instance from the database upon merge (the classical behavior of this method is that it loads the current data from the database which is merged with the given data). so setting dont_load=True will prevent these loads from happening. we also have some fairly important fixes to dont_load=True in the current trunk which will be out in version 0.4.2, so if you are getting into heavy merge() usage and you need to use the dont_load flag (which is strictly for performance reasons), you might want to go on trunk for awhile. The other option here is to move the object completely from the background to the foreground session. to do this, you would expunge() it from the background session, and then update() it into the target session. this is a simpler operation than merge since nothing is being copied. but youd want to ensure the objects youre moving werent part of some larger collection thats still sitting in the background session. hope this helps... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Fwd: [elixir] warnings on exit
Since this is not specific to Elixir and I don't know what could be the problem, I'm forwarding this to the SQLAlchemy list. You can watch that list for the answer (which will hopefully be given) or wait until I forward that answer to the Elixir list. -- Forwarded message -- From: Ryszard Szopa [EMAIL PROTECTED] Date: Dec 13, 2007 5:25 PM Subject: [elixir] warnings on exit To: SQLElixir [EMAIL PROTECTED] Hello all, When my python script using Elixir exits, it outputs a lot of warnings. Like: ... Exception exceptions.TypeError: 'NoneType' object is not callable in bound method InstanceState.__cleanup of sqlalchemy.orm.attributes.InstanceState object at 0x870a22c ignored Exception exceptions.TypeError: 'NoneType' object is not callable in bound method InstanceState.__cleanup of sqlalchemy.orm.attributes.InstanceState object at 0x86fee6c ignored Exception exceptions.TypeError: 'NoneType' object is not callable in bound method InstanceState.__cleanup of sqlalchemy.orm.attributes.InstanceState object at 0x86fedac ignored ... Do you have any idea what can be the reason of this behavior? I cannot really identify any part of my code that should be responsible for it. Thanks in advance, -- Richard -- Gaƫtan de Menten http://openhex.org --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Double joined polymorphic inheritance ?
Hi, I'd like to know if it's possible to have multiple level of inheritance. Please find attached a test case where I'd like to have Site to inherit from Company and also be the base table for SiteClient and SiteSupplier. I guess I'd need a mix of the following syntax (from the test): #site_mapper = mapper(Site, site_table, inherits=Company, polymorphic_identity='site') site_mapper = mapper(Site, site_table, polymorphic_on=site_table.c.type, polymorphic_identity='site') Is that possible ? Regards, -- Alexandre CONRAD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~--- SA_double_inheritance.py Description: application/python
[sqlalchemy] Re: Sessions and threads, find in one thread, use in another
On Dec 13, 2007 10:47 AM, Michael Bayer [EMAIL PROTECTED] wrote: On Dec 13, 2007, at 9:55 AM, Allen Bierbaum wrote: In my current application I am running a rather expensive query in a background thread, but then I need to use the results in the foreground thread. The object I find has a great deal of lazy evaluated properties that link it to several other mapped objects. As it stands now, the application is only following the lazy properties when it uses the object in the primary thread. The has multiple engines connected to multiple databases. I have a separate session for each database for each thread. (Note: right now I am doing this manually but I am debating whether I should be using something like SessionContext.) What I am worried about is that by querying the initial parent object in the background thread and then using it's lazy props in the foreground thread, I think SA is probably using the background session to evaluate these links. Is there a recommended way to deal with a situation like this? In other words, what is the recommended practice for moving, reusing objects from a session across multiple threads. Is there some way to remap the object and attach it to the foreground session? theres two general options here. the most appropriate way to move the object between sessions is to use session.merge(). this will create a copy of the object in the target session, which is returned, leaving the old one unchanged, so that it can additionally be merged elsewhere. as of version 0.4.1 we added a flag to merge called dont_load which prevents merge() from reloading the instance from the database upon merge (the classical behavior of this method is that it loads the current data from the database which is merged with the given data). so setting dont_load=True will prevent these loads from happening. we also have some fairly important fixes to dont_load=True in the current trunk which will be out in version 0.4.2, so if you are getting into heavy merge() usage and you need to use the dont_load flag (which is strictly for performance reasons), you might want to go on trunk for awhile. The other option here is to move the object completely from the background to the foreground session. to do this, you would expunge() it from the background session, and then update() it into the target session. this is a simpler operation than merge since nothing is being copied. but youd want to ensure the objects youre moving werent part of some larger collection thats still sitting in the background session. hope this helps... That helps. Thanks. I will try to start using merge along with SessionContext to fix up my threading issues. Thanks, Allen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Fetchall() in 0.4x
Just noticed that ResultProxy.fetchall() is a bit broken in 0.4x (I think it's for queries that do not populate the DBAPI cursor.description). In my case, it's executing a stored procedure that returns data: S.execute('exec schema.storedproc 1234').fetchall() Traceback (most recent call last): File msh.py, line 49, in ? print S.execute('schema.storedproc 1234').fetchall() File /usr/lib/python2.4/site-packages/SQLAlchemy- 0.4.2dev_r3844-py2.4.egg/sqlalchemy/engine/base.py, line 1249, in __repr__ return repr(tuple(self)) File /usr/lib/python2.4/site-packages/SQLAlchemy- 0.4.2dev_r3844-py2.4.egg/sqlalchemy/engine/base.py, line 1241, in __iter__ yield self.__parent._get_col(self.__row, i) File /usr/lib/python2.4/site-packages/SQLAlchemy- 0.4.2dev_r3844-py2.4.egg/sqlalchemy/engine/base.py, line 1500, in _get_col type_, processor, index = self._key_cache[key] AttributeError: 'ResultProxy' object has no attribute '_key_cache' ResultProxy has no --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Fetchall() in 0.4x
On Dec 13, 2007, at 11:51 PM, Rick Morrison wrote: Just noticed that ResultProxy.fetchall() is a bit broken in 0.4x (I think it's for queries that do not populate the DBAPI cursor.description). In my case, it's executing a stored procedure that returns data: S.execute('exec schema.storedproc 1234').fetchall() Traceback (most recent call last): File msh.py, line 49, in ? print S.execute('schema.storedproc 1234').fetchall() File /usr/lib/python2.4/site-packages/SQLAlchemy- 0.4.2dev_r3844- py2.4.egg/sqlalchemy/engine/base.py, line 1249, in __repr__ return repr(tuple(self)) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2dev_r3844- py2.4.egg/sqlalchemy/engine/base.py , line 1241, in __iter__ yield self.__parent._get_col(self.__row, i) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2dev_r3844- py2.4.egg/sqlalchemy/engine/base.py, line 1500, in _get_col type_, processor, index = self._key_cache[key] AttributeError: 'ResultProxy' object has no attribute '_key_cache' returns rows but has no cursor.description ? we can work around it, setting _key_cache to something with just an integer __getitem__, if we're known to return rows but no description is there. But it sounds more like an adodbap/pymssql/whatever bug. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---