[sqlalchemy] SQLAlchemny SAWarning - which Session Query is giving this?
Hello: SQLAlchemnt 0.6.5 - in stderr log we continuously see the following warning logged. My understanding is this is due to IN () generated with EMPTY sequence. However on turning on SQL Alchemny Log, I do not find ant statement that has where clause with EMPTY IN sequence for predicate suspiciousevents.rule_id. Any suggestions how to find due to which session query this warning is coming? 2011-04-12 15:23:01,835 INFO sqlalchemy.engine.base.Engine.0x...b6d0 ('multicore', 2120) /opt/python26/lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/ sqlalchemy/sql/expression.py:1660: SAWarning: The IN-predicate on suspiciousevents.rule_id was invoked with an empty sequence. This results in a contradiction, which nonetheless can be expensive to evaluate. Consider alternative strategies for improved performance. return self._in_impl(operators.in_op, operators.notin_op, other) Regards Harish -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Custom MySQL Socket with SQL Alchemy
That happened to be the case. On turning on SQL Debug we found this in Apache Log. [Mon Apr 04 18:49:26 2011] [error] 2011-04-04 18:49:26,330 INFO sqlalchemy.engine.base.Engine.0x...b5d0 () [Mon Apr 04 18:49:26 2011] [error] /home/topsight/code/tsweb/tsweb/ model/__init__.py:7: SAWarning: At least one scoped session is already present. configure() can not affect sessions that have already been created. [Mon Apr 04 18:49:26 2011] [error] Session.configure(bind=engine) There was a Session.configure() in one of the files, we commented that and things have been fine. Wonder why it worked when we restarted Apache Web Server (using mod_wsgi), and then gave errors after same page was visited few times On Apr 5, 6:30 am, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 4, 2011, at 9:07 PM, Harish Tejwani wrote: We are trying to point SQLAlchemny (0.6.5 engine) to use custom MySQL Socket using URL Parameter as below WRITEDATASTORE = topsight_config.DATASTORE + '?unix_socket=/opt/mysql/ mysql.sock' writeengine = create_engine(WRITEDATASTORE, echo=topsight_config.SQL_DEBUG, pool_recycle=3600) However this does not seem to work always. The application does work, however for many queries we get the following error in Log File Why is engine defaulting to /var/lib/mysql/mysql.sock? Is there another way to set this value while creating the Egine That's the correct way to set the value and it works. SQLAlchemy knows nothing about this parameter and it is passed straight through. If it is not always working, that strongly suggests your application is calling a different create_engine() statement elsewhere which is used in some cases. I'd grep for it. [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/home/ topsight/code/tsweb/data/templates/status.html.py', line 80 in render_body [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] ruleset = dict((s[0],s) for s in se.all()) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ query.py', line 1576 in all [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return list(self) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ query.py', line 1688 in __iter__ [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return self._execute_and_instances(context) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ query.py', line 1693 in _execute_and_instances [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] mapper=self._mapper_zero_or_none()) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ session.py', line 728 in execute [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return self._connection_for_bind(engine, close_with_result=True).execute( [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ session.py', line 669 in _connection_for_bind [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return self.transaction._connection_for_bind(engine) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ session.py', line 336 in _connection_for_bind [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] conn = bind.contextual_connect() [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ engine/base.py', line 1829 in contextual_connect [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] self.pool.connect(), [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ pool.py', line 183 in connect [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return _ConnectionFairy(self).checkout() [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ pool.py', line 370 in __init__ [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] rec = self._connection_record = pool.get() [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ pool.py', line 214 in get [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return self.do_get() [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ pool.py', line 733 in do_get
[sqlalchemy] Custom MySQL Socket with SQL Alchemy
We are trying to point SQLAlchemny (0.6.5 engine) to use custom MySQL Socket using URL Parameter as below WRITEDATASTORE = topsight_config.DATASTORE + '?unix_socket=/opt/mysql/ mysql.sock' writeengine = create_engine(WRITEDATASTORE, echo=topsight_config.SQL_DEBUG, pool_recycle=3600) However this does not seem to work always. The application does work, however for many queries we get the following error in Log File Why is engine defaulting to /var/lib/mysql/mysql.sock? Is there another way to set this value while creating the Egine [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/home/ topsight/code/tsweb/data/templates/status.html.py', line 80 in render_body [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] ruleset = dict((s[0],s) for s in se.all()) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ query.py', line 1576 in all [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return list(self) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ query.py', line 1688 in __iter__ [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return self._execute_and_instances(context) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ query.py', line 1693 in _execute_and_instances [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] mapper=self._mapper_zero_or_none()) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ session.py', line 728 in execute [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return self._connection_for_bind(engine, close_with_result=True).execute( [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ session.py', line 669 in _connection_for_bind [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return self.transaction._connection_for_bind(engine) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/ session.py', line 336 in _connection_for_bind [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] conn = bind.contextual_connect() [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ engine/base.py', line 1829 in contextual_connect [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] self.pool.connect(), [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ pool.py', line 183 in connect [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return _ConnectionFairy(self).checkout() [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ pool.py', line 370 in __init__ [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] rec = self._connection_record = pool.get() [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ pool.py', line 214 in get [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return self.do_get() [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ pool.py', line 733 in do_get [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] con = self.create_connection() [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ pool.py', line 148 in create_connection [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return _ConnectionRecord(self) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ pool.py', line 254 in __init__ [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] self.connection = self.__connect() [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ pool.py', line 320 in __connect [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] connection = self.__pool._creator() [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/ lib/python2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/ engine/strategies.py', line 76 in connect [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] return dialect.connect(*cargs, **cparams) [Mon Apr 04 17:48:02 2011] [error] [client 10.200.22.204] File '/usr/
[sqlalchemy] SQL Alchemy Out of memory (re-posted)
Michael suggested to repost this. We are running on a fairly beefy Linux machine and SQLAlchemny 0.6.5 We have started getting getting Out of Memory errors like below (MySQL runs on same machine). Any ideas or suggestion why this could be happening and how to go about identifying root cause of this Out of memory (Needed 18653760 bytes) Traceback (most recent call last): File /home/topsight/code/topsight-multicore.py, line 36, in module rules[rule].execute() File /home/topsight/code/objects.py, line 1259, in execute runresult.flag(self.id, update_flagtime=self.update_flagtime) File /home/topsight/code/objects.py, line 669, in flag for e in self.all(): File /opt/python26/lib/python2.6/site-packages/SQLAlchemy-0.6.5- py2.6.egg/sqlalchemy/orm/query.py, line 1576, in all return list(self) File /opt/python26/lib/python2.6/site-packages/SQLAlchemy-0.6.5- py2.6.egg/sqlalchemy/orm/query.py, line 1790, in instances fetch = cursor.fetchall() File /opt/python26/lib/python2.6/site-packages/SQLAlchemy-0.6.5- py2.6.egg/sqlalchemy/engine/base.py, line 2490, in fetchall l = self.process_rows(self._fetchall_impl()) File /opt/python26/lib/python2.6/site-packages/SQLAlchemy-0.6.5- py2.6.egg/sqlalchemy/engine/base.py, line 2459, in _fetchall_impl self._non_result() File /opt/python26/lib/python2.6/site-packages/SQLAlchemy-0.6.5- py2.6.egg/sqlalchemy/engine/base.py, line 2464, in _non_result This result object does not return rows. sqlalchemy.exc.ResourceClosedError: This result object does not return rows. It has been closed automatically. -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: SQL Alchemy Out of memory (re-posted)
Turning on logging gives lots of logs, anyway we also thought that self.all() is returning a very large data-set (we don't have BLOBs) Are there any limits and is there anyway we can increase the memory here, maybe of python process itself Is there any other solution you suggest if select itself very returns large rows (some times) but is limited size most of time? How to handle that in application = we would like to keep logic generic On Mar 31, 8:47 am, Michael Bayer mike...@zzzcomputing.com wrote: so because its a query that is a SELECT and then MySQLdb is not returning a description, I'm suspecting you might be loading a very large BLOB or a very large result set on a particular query. I'd look into logging what you are sending to the database, and particularly using the debugger or similar at that point if the error is reproducible in a development environment, to see what was passed. On Mar 31, 2011, at 11:32 AM, Harish Tejwani wrote: Michael suggested to repost this. We are running on a fairly beefy Linux machine and SQLAlchemny 0.6.5 We have started getting getting Out of Memory errors like below (MySQL runs on same machine). Any ideas or suggestion why this could be happening and how to go about identifying root cause of this Out of memory (Needed 18653760 bytes) Traceback (most recent call last): File /home/topsight/code/topsight-multicore.py, line 36, in module rules[rule].execute() File /home/topsight/code/objects.py, line 1259, in execute runresult.flag(self.id, update_flagtime=self.update_flagtime) File /home/topsight/code/objects.py, line 669, in flag for e in self.all(): File /opt/python26/lib/python2.6/site-packages/SQLAlchemy-0.6.5- py2.6.egg/sqlalchemy/orm/query.py, line 1576, in all return list(self) File /opt/python26/lib/python2.6/site-packages/SQLAlchemy-0.6.5- py2.6.egg/sqlalchemy/orm/query.py, line 1790, in instances fetch = cursor.fetchall() File /opt/python26/lib/python2.6/site-packages/SQLAlchemy-0.6.5- py2.6.egg/sqlalchemy/engine/base.py, line 2490, in fetchall l = self.process_rows(self._fetchall_impl()) File /opt/python26/lib/python2.6/site-packages/SQLAlchemy-0.6.5- py2.6.egg/sqlalchemy/engine/base.py, line 2459, in _fetchall_impl self._non_result() File /opt/python26/lib/python2.6/site-packages/SQLAlchemy-0.6.5- py2.6.egg/sqlalchemy/engine/base.py, line 2464, in _non_result This result object does not return rows. sqlalchemy.exc.ResourceClosedError: This result object does not return rows. It has been closed automatically. -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/sqlalchemy?hl=en. -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Formatting return of 'query'
Hello, Can a query be written to return required columns along with some delimiter? Example : #User is a class, it has firstname, lastname, age, password q = session.query(User.firstname,User.lastname,User.age,User.password).all() #this would return [(fname,lname,22,pwd),] How can I modify this query to return something like : [(fname~lname~22~pwd)...] with '~' being preferred delimiter. I would like to know if I can return something like above directly from the query itself. Thanks, Harish --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Query.delete() issues a select before delete?
Hello All, I found this : #s is a session object #Director is a class s.query(Director).filter(Director.name == 'Dir30').delete() 2009-06-01 16:17:00,750 INFO sqlalchemy.engine.base.Engine.0x...9a10 SELECT director.id AS director_id FROM director WHERE director.name = ? 2009-06-01 16:17:00,796 INFO sqlalchemy.engine.base.Engine.0x...9a10 ['Dir30'] 2009-06-01 16:17:00,875 INFO sqlalchemy.engine.base.Engine.0x...9a10 DELETE FROM director WHERE director.name = ? 2009-06-01 16:17:00,937 INFO sqlalchemy.engine.base.Engine.0x...9a10 ['Dir30'] 1 Is there any reason behind for SELECT being issued before a DELETE? Regards, Harish --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Query.delete() doesn't cascade on Sqlite
Thanks for your thoughts! I was wondering which will be more economical in terms of memory and cpu 1. Let SQLA manage cascades. - query.all() brings the entire table into memory. I am trying to figure out how to manage it with cursors. - There is a processing overhead for SQLA to convert RDBMS records to Objects. - More CPU 2. Triggers on SQLite. - http://www.sqlite.org/tempfiles.html, seems that SQLite maintains transaction logs in a journal file. I am doing more testing to find out the best option. Regards, Harish On Fri, May 29, 2009 at 9:35 PM, Randy Syring ra...@rcs-comp.com wrote: Ah...missed that part. Well, the triggers are fired per-row I believe. So, if you don't use a transaction explicitly, and just let SQLite run without one, it will be slower, but the resource usage should be much less. On May 29, 10:31 am, Mike Conley mconl...@gmail.com wrote: Harish said it was an embedded system, probably all resources are pretty severely restricted. -- Mike Conley On Fri, May 29, 2009 at 9:44 AM, Randy Syring ra...@rcs-comp.com wrote: Mike, Well...I am not sure. I thought SQLite held transaction details in a .journal file and not in memory. I thought that the memory use might actually be a Python problem and not a result of SQLite. If my thoughts are correct, using the FK approach should keep deleting the children in SQLite, which should use a journal file, which should reduce memory usage. But I could be wrong. :) On May 29, 9:28 am, Mike Conley mconl...@gmail.com wrote: Randy, Interesting approach to foreign key management. Harish indicates he is having a problem with restricted memory. Won't that still be true with triggers? After all, if the problem is that the transaction is too big, it will still be too big with all the pending deletes executed in a trigger. -- Mike Conley On Fri, May 29, 2009 at 8:47 AM, Randy Syring ra...@rcs-comp.com wrote: Another solution is to use triggers in SQLite to enforce FK relationships. http://www.sqlite.org/cvstrac/wiki?p=ForeignKeyTriggers http://code.google.com/p/sqlitefktg4sa/ On May 29, 6:59 am, Mike Conley mconl...@gmail.com wrote: One solution is to change the commit strategy; issue commits periodically during the loop. parentlist = session.query(Parent).all() count = 0 for parent in parentlist: session.delete(parent) count += 1 if count % 100 == 0 # use whatever frequency is needed count = 0 session.commit() if count 0: session.commit() # this gets the last group of deletes The disadvantage of this approach is that you lose the ability to rollback the entire delete process, and now must handle that problem with application design. -- Mike Conley On Fri, May 29, 2009 at 4:08 AM, Harish Vishwanath harish.shas...@gmail.com wrote: Hello, I am running Sqlite/SQLA/Elixir on an embedded system. I have different classes with OneToMany relationships and I have configured cascade = all, delete, delete-orphan correctly on them. However, for this to work, I should do something like : parentlist = session.query(Parent).all() for parent in parentlist: session.delete(parent)# session.commit() The above chokes the system since it has limited memory. The statement below : session.query(Parent).delete(), issues DELETE FROM PARENT; This is memory efficient, but it doesn't delete the child objects since Sqlite doesn't impose FK constraints. Is there any way to solve this problem? Regards, Harish --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Query.delete() doesn't cascade on Sqlite
Hello, I am running Sqlite/SQLA/Elixir on an embedded system. I have different classes with OneToMany relationships and I have configured cascade = all, delete, delete-orphan correctly on them. However, for this to work, I should do something like : parentlist = session.query(Parent).all() for parent in parentlist: session.delete(parent)# session.commit() The above chokes the system since it has limited memory. The statement below : session.query(Parent).delete(), issues DELETE FROM PARENT; This is memory efficient, but it doesn't delete the child objects since Sqlite doesn't impose FK constraints. Is there any way to solve this problem? Regards, Harish --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Questions on SQLA Queries
Thanks! Could you elaborate on how you use the map function? I couldn't find it myself in the docs. Regards, Harish On Wed, May 27, 2009 at 3:07 PM, Timothy N. Tsvetkov timothy.tsvet...@gmail.com wrote: Q1. Good question %) I didn't find anything about it in docs (but i didn't search a lot), so i use map function to convert it to a list you want. And I think it is the right solution. Because if you query for more then one column (session.query(User.is, User.name).all()) a list of tuples is what you want to get as a result. So i think it is good, that it works the same way for one or more then one query params. On May 26, 9:10 pm, Harish Vishwanath harish.shas...@gmail.com wrote: Hello, Question 1: When there is a query like below : q = session.query(User.name) #(User is a class) and when I do q.all(), a list of tuples (User.name,) is returned though a single column is asked for. Is there a way to get a list directly from q.all() when a single column is required? Question 2: I need to delete a bulky table and I want to print diagnostics after n number of deletes. Is there a way to use Query object so that a SQL statement like below can be generated? delete from movie where year in (select top 30 year from movie where year 50); , so that a message can be logged after every 30 deletes. I am using Sqlite DB. Regards, Harish --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Questions on SQLA Queries
Hello, Question 1: When there is a query like below : q = session.query(User.name) #(User is a class) and when I do q.all(), a list of tuples (User.name,) is returned though a single column is asked for. Is there a way to get a list directly from q.all() when a single column is required? Question 2: I need to delete a bulky table and I want to print diagnostics after n number of deletes. Is there a way to use Query object so that a SQL statement like below can be generated? delete from movie where year in (select top 30 year from movie where year 50); , so that a message can be logged after every 30 deletes. I am using Sqlite DB. Regards, Harish --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: SQLAlchemy 0.5 Released
Congratulations! And many thanks for the wonderful SQLA! Cheers. On Wed, Jan 7, 2009 at 1:12 AM, Michael Bayer mike...@zzzcomputing.comwrote: Hello list - I am pleased to announce the release of SQLAlchemy 0.5.0, the first official release in the 0.5 series. This series has been in the making since the Pycon 2008 sprints, where we first began reorganizing the ORM attribute system and adding comprehensive rollback and SAVEPOINT support to the session. To really get a sense of what's new, the http://www.sqlalchemy.org/trac/wiki/05Migration document points to most of it, and a good read of the ORM tutorial and the session documentation illustrate the major paradigm shifts of the 0.5 series. The most profound changes are: * Query can now select any combination of entities/columns, ORM enabled or not. * The Declarative approach is widely tested and should be considered a first choice for many applications. * The Session actively expires its state after a commit operation and can revert its internal state after a rollback (all of which is configurable since it results in a lot more SQL being issued). SAVEPOINTs are very usable. * Query's ability to create joins automatically or semi- automatically using query.join() is greatly enhanced. * Query can issue updates and deletes directly based on criterion. * The joined and single table inheritance systems, particularly from a Query perspective, are dramatically improved. * The ORM has many new extension points including AttributeExtension, SessionExtension, and comparator_factory. * The method of configuring schema-level column defaults has been simplified. * The MS-SQL dialect is vastly improved and actively supported thanks to the tireless efforts of Michael Trier. * Speed increases are in the 20% range over 0.4. * The documentation has been converted to Sphinx, and a new searchable API Reference section has been created. * Python 2.3 is no longer supported. The 0.5 series was prereleased through a series of four release candidates over a period of many months, so many production applications are already using the 0.5 series of SQLAlchemy, including Armin Ronacher's new blogging application Zine: http://zine.pocoo.org/ . Also in development is the 0.6 series of SQLAlchemy, which is where we've targeted our dialect overhaul that will allow DBAPIs to interact with database dialects in an agnostic way - this will lead to easy support to backend-agnostic dialects like zxJDBC, mxODBC, pyodbc, as well as alternate dialects like pg8000 which are proving to be faster to the punch in terms of Py3K. Our Py3K support is targeted towards 0.6 where we're anticipating that its DBAPI agnosticism will allow us to mobilize quickly towards new Py3K drivers as they are released. Download SQLAlchemy 0.5 at: http://www.sqlalchemy.org/download.html Migration: http://www.sqlalchemy.org/trac/wiki/05Migration Changelog: http://www.sqlalchemy.org/trac/browser/sqlalchemy/tags/rel_0_5_0/CHANGES --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Fastest Way of removing an object from session.identity_map
Hello, I have a scenario like below : - Session has weak_identity_map set to true. Therefore session is self pruning. - In some situations, the session might contain object references, which have been deleted by other sessions from the database. - In such cases, I want to remove the references of those deleted objects from this session's identity_map. - Running a gc.collect() could be expensive. - I just have primary key of the object that got deleted from another session. Which is the fastest way to remove this specific object from the session's identity_map? Currently I am doing something like below : # dkey is a tuple and will have the primary key of the object that just got deleted from the db through another session. dobj = None for obj in session.identity_map: c, k = obj #extract class and the primary key tuple from the object. if k == dkey: dobj = obj #get the object reference to be deleted. break #The session wont contain multiple references to the same obj anyway. session.identity_map.remove_key(dobj) #delete that object from the session. I am worried about the iteration that I do, which could consume significant time in case session has a lot of objects after a bulk query/insertion etc., Is there a better way to do this? Thanks for the help! Regards, Harish --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Problem in working with two sessions to the same database.
Hello All, I have a situation like this : Thread T1, has session T1Session. Thread T2, has session T2Session. They both bind to the same database. Now, I have scenario like below : u1 = User() u2 = User() u3 = User()#All these are Entity objects, , and are primary keys. T1Session.add( u1, u2 and u3 ) T1Session.flush() T1Session.commit() # T1Session.identity_map will have the 3 user objects. li = T2Session.Query(Users).all() for u in li: T2Session.delete(u) T2Session.flush() T2Session.commit() #But T1Session.identity_map still has the 3 user objects. a = User() b = User() T1Session.add(a) T1Session.add(b) T1Session.flush() Throws an exception : raise exc.FlushError(New instance %s with identity key %s conflicts with persistent instance %s % (state_str(state), str(instance_key), state_str(existing))) Clearing T1Session before adding a and b would work. But I dont have that much control over T1Session, and setting up a mechanism to do this will turn to be very complicated in my app's scenario. Is there any way to make T1Session aware that it has invalid data in its identity_map immediately after T2Session deleted those users? Thanks for the help! Cheers, Harish --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Invalid Request Error at session level.
Hello, I am using SQLA 0.5rc2 on Py 2.5.2 with Elixir 0.6. I have a multithreaded application, and each thread gets a separate session object. All of them use the same disk based database. I get the below exception : Exception in thread RSIHostDBSync: Traceback (most recent call last): File c:\python25\lib\threading.py, line 486, in __bootstrap_inner self.run() File O:\RecogSys\src\python\RSITerm\RSIHostDBSync.py, line 978, in run InteractionsSent, InteractionsRemaining = self.SendInteractions() File O:\RecogSys\src\python\RSITerm\RSIHostDBSync.py, line 1366, in SendInte ractions iaKeyList = list(self.rsiDB.InteractionDB().keys()) File O:\RecogSys\src\python\RSITerm\SQLConvert\InteractionDBDict.py, line 24 , in keys return self.dbo.InteractionDBDict_Keys() File O:\RecogSys\src\python\RSITerm\SQLConvert\SqlDB.py, line 1045, in Inter actionDBDict_Keys filter_by(SentFlag = 0).all(): File c:\python25\lib\site-packages\sqlalchemy-0.5.0rc2-py2.5.egg\sqlalchemy\o rm\query.py, line 990, in all return list(self) File c:\python25\lib\site-packages\sqlalchemy-0.5.0rc2-py2.5.egg\sqlalchemy\o rm\query.py, line 1078, in __iter__ return self._execute_and_instances(context) File c:\python25\lib\site-packages\sqlalchemy-0.5.0rc2-py2.5.egg\sqlalchemy\o rm\query.py, line 1081, in _execute_and_instances result = self.session.execute(querycontext.statement, params=self._params, m apper=self._mapper_zero_or_none(), _state=self._refresh_state) File c:\python25\lib\site-packages\sqlalchemy-0.5.0rc2-py2.5.egg\sqlalchemy\o rm\session.py, line 749, in execute return self.__connection(engine, close_with_result=True).execute( File c:\python25\lib\site-packages\sqlalchemy-0.5.0rc2-py2.5.egg\sqlalchemy\o rm\session.py, line 716, in __connection return self.transaction._connection_for_bind(engine) File c:\python25\lib\site-packages\sqlalchemy-0.5.0rc2-py2.5.egg\sqlalchemy\o rm\session.py, line 309, in _connection_for_bind self._assert_is_active() File c:\python25\lib\site-packages\sqlalchemy-0.5.0rc2-py2.5.egg\sqlalchemy\o rm\session.py, line 244, in _assert_is_active The transaction is inactive due to a rollback in a InvalidRequestError: The transaction is inactive due to a rollback in a subtrans action. Issue rollback() to cancel the transaction. I am guarding my commits with a mutex, but the queries are unguarded. Before I get the above exception, I dont see any other messages regarding the transaction rollback that is mentioned here before this exception occurs. Could this be a problem with the way I have implemented sessions? If one of the session is committing on the database and the other one is trying to query, would this problem arise? I am not very sure on how connection objects are created during this scenario. Appreciate your help. Regards, Harish --~--~-~--~~~---~--~~ 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: Trouble with Strings getting converted to Unicode types
Hello, Thanks for your suggestion. I wanted to ask one more thing. I am using Sqlite with SQLA. Its a multi threaded application, but each thread gets its own session/engine. But, since it is Sqlite, isn't there just only one connection? Adding a Pool Listener, will make extra function calls every time a connect() is requested. This is an embedded system, and I am little worried if that could degrade performance. Would appreciate your comments! Thanks again for the help! Regards, Harish On Tue, Nov 25, 2008 at 11:07 AM, Michael Bayer [EMAIL PROTECTED]wrote: On Nov 24, 2008, at 11:47 PM, Harish Vishwanath wrote: Hello, Thanks for your reply. Please see the below implementation : *Implementation 1:* def my_con_func(): ... print My Connection func ... import sqlite3.dbapi2 as sqlite ... con = sqlite.connect(:memory:) ... con.text_factory=str ... return con ... engine = create_engine(sqlite:///,creator=my_con_func) engine Engine(sqlite:///) engine.connect() My Connection func sqlalchemy.engine.base.Connection object at 0x01B1ADB0 engine.connect().connection.connection.text_factory type 'str' *Implementation 2:* anotherengine = create_engine(sqlite:///:memory:) anotherengine.connect().connection.connection.text_factory = str I would like to know which one is better, since I am afraid if I am missing some create_engine inbuilt implementation while returning custom connection object (in Implementation 1). Please let me know your suggestion. go with this one: from sqlalchemy.interfaces import PoolListener class SetTextFactory(PoolListener): def connect(self, dbapi_con, con_record): dbapi_con.text_factory = str engine = create_engine('sqlite://', listeners=[SetTextFactory()]) implementation 1 is fine, you can stay with it if you want - I just think creator is a little klunky since you have to re-import sqlite and connect manually. implementation 2 will only work for a single-threaded application and will break if the pool implementation is changed, unless you set-up text_factory every time connect() is called (which is usually impossible). --~--~-~--~~~---~--~~ 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: Trouble with Strings getting converted to Unicode types
Hello, Thanks for your input. I consulted PySqlite's docs : They have something like Connection.text_factory, which is by default set to Unicode. If it is set to str, that is., connection.text_factory = str, then it wont convert strings to Unicode. I glanced thru SQLA code, but I couldn't find a place where I can pass this option to SQLA so that it can in turn use the above option while obtaining the connection from PySqlite. Please let me know if there is a way of achieving this. Thank! Regards, Harish On Tue, Nov 18, 2008 at 9:47 PM, Michael Bayer [EMAIL PROTECTED]wrote: pysqlite always returns Python unicode objects and this is outside of the realm of SQLAlchemy. I'm not familiar with a pysqlite option to change this but you should consult their site for any options related to it. Harish Vishwanath wrote: Hello All, I am using Elixir 0.6.1 over SQLA 0.5rc2. Consider the below : from elixir import * class A(Entity): *... name = Field(String(40))* ... class B(A): *... address = Field(String(40))* ... engine = sqlite:///c:\\temp\\2.sqlite metadata.bind = engine setup_all(True) a = A(name=A) type(a.name) type 'str' b = B(name=B,address=B'sAddress) type(b.name) type 'str' type(b.address) type 'str' type(a.row_type) type 'NoneType' session.flush() session.commit() * d = session.query(A)[0] d.name u'A' type(d.name) type 'unicode' d.row_type u'a' * from elixir import options * options.DEFAULT_POLYMORPHIC_COL_NAME 'row_type' options.POLYMORPHIC_COL_TYPE String(length=40, convert_unicode=False, assert_unicode=None) options.POLYMORPHIC_COL_SIZE 40* Though I declare fields of Class A and B as strings, when I retrieve the objects back from database, the are automatically getting converted to Unicode. Also, the default polymorphic column type is String, but row_type after retrieval is coming back as unicode. When I query SQLite, I see normal strings : sqlite select * from __main___a; 1|A|a| 2|B|b|B'sAddress I donot want my strings to get converted to Unicode, since I am having issues with marshalling and transmitting unicode objects over the network. Is there any option I am missing? Kindly let me know. -- Regards, Harish -- Regards, Harish --~--~-~--~~~---~--~~ 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] Trouble with Strings getting converted to Unicode types
Hello All, I am using Elixir 0.6.1 over SQLA 0.5rc2. Consider the below : from elixir import * class A(Entity): *... name = Field(String(40))* ... class B(A): *... address = Field(String(40))* ... engine = sqlite:///c:\\temp\\2.sqlite metadata.bind = engine setup_all(True) a = A(name=A) type(a.name) type 'str' b = B(name=B,address=B'sAddress) type(b.name) type 'str' type(b.address) type 'str' type(a.row_type) type 'NoneType' session.flush() session.commit() * d = session.query(A)[0] d.name u'A' type(d.name) type 'unicode' d.row_type u'a' * from elixir import options * options.DEFAULT_POLYMORPHIC_COL_NAME 'row_type' options.POLYMORPHIC_COL_TYPE String(length=40, convert_unicode=False, assert_unicode=None) options.POLYMORPHIC_COL_SIZE 40* Though I declare fields of Class A and B as strings, when I retrieve the objects back from database, the are automatically getting converted to Unicode. Also, the default polymorphic column type is String, but row_type after retrieval is coming back as unicode. When I query SQLite, I see normal strings : sqlite select * from __main___a; 1|A|a| 2|B|b|B'sAddress I donot want my strings to get converted to Unicode, since I am having issues with marshalling and transmitting unicode objects over the network. Is there any option I am missing? Kindly let me know. -- Regards, Harish --~--~-~--~~~---~--~~ 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] Force Load all attributes during a Query
Hello, Is there a way to tell the session to force load all the attributes of an object during a query? (i,e even if it is already present in the Identity Map?). For some reason, auto_expire_on_commit, if set to True is not working well with my app. I always do a session.query(object) before getting an object. If there is a way to force all my queries by default to load all attributes of the object, if would be great. -- Regards, Harish --~--~-~--~~~---~--~~ 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: Orphans not deleted using cascade parameter
Try putting the cascade=all, delete, delete-orphan on OneToMany side of the Relationship. On Wed, Aug 27, 2008 at 9:05 AM, Michael Bayer [EMAIL PROTECTED]wrote: On Aug 26, 2008, at 6:08 PM, Alex Mathieu wrote: Let's say I have two classes: class PublicationElement(Entity): using_options(tablename='publication') sections = OneToMany('SectionElement') covers = OneToMany('PublicationCoverElement') publication_id = Field(Integer, primary_key=True) name = Field(Unicode(255)) short_name = Field(Unicode(30)) app_download_link = Field(UnicodeText) class SectionElement(Entity): using_options(tablename='section') publication = ManyToOne('PublicationElement', colname=publication_id, cascade=all,delete-orphan) section_id = Field(Integer, primary_key=True) name = Field(Unicode(255)) articles_on_cover = Field(Integer) articles_on_sub_cover = Field(Integer) ad_on_top = Field(Boolean) ad_on_bottom = Field(Boolean) poll_rate_minutes = Field(Integer) poll_weight = Field(Integer) show_sub_cover = Field(Boolean) If I delete a PublicationElement entity, all the related SectionElement entities get their publication_id key set to 0... and I just can't figure it out why. I've been digging through the web, but wasn't able any answer... Maybe I putted my cascade argument at the wrong place ? Not sure to get it... this mapping suggests that the deletion of a SectionElement will cause the deletion of a related PublicationElement, but not the other way around. The cascade would have to be moved to the PublicationElement.sections side of the relation.Im not sure where the 0 is coming from, SQLAlchemy will normally set foreign key references to NULL if no row is related. -- Regards, Harish --~--~-~--~~~---~--~~ 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: Fwd: Autoexpire on commit is causing problems?
Hello, Thank you very much for your reply! Each thread gets its own session. The first thread, after adding a User object, appends its primary key into a global List. The other thread which is trying to modify the object : - Pops an id from the global list - Queries the object from the DB using its own session using the id popped. This query adds the object to the second threads session, right? Sharing the object across threads works against the transaction model which you are trying to take advantage of. Your second thread is in its own transaction, and should be loading all of its information from that transaction. By hitting user.UserID in the second thread, you're attempting to access database data from the original transaction which user is still associated with and concurrency related issues are occuring. The first thread is trying to put the UserID into the gloabl list (this way, it passes the id of object it just added to the second thread). So, in the line where it is trying to USERIDLIST.append(user.userid) in the first thread. When expire_on_commit is set to True, this statement issues an internal query, and I get this exception. PS : I add around 100 users in the thread, and the below exception occurs randomly during the addition. Any inputs? Thank you so much again! On Mon, Aug 25, 2008 at 8:12 PM, Michael Bayer [EMAIL PROTECTED]wrote: On Aug 25, 2008, at 12:24 AM, Harish K Vishwanath wrote: The line USERIDLIST.append(user.UserID),is trying to append the newly added (to the database) user object's primary key (UserID) into a List in one thread , to be used by another thread which tries to modify the object. Its throwing up exceptions there. This error will go away if I set expire_on_commit = False. From all indications, this is concurrent Session access which is not supported - any object which is associated with a Session can call upon its owning Session at any time. Sharing the object across threads works against the transaction model which you are trying to take advantage of. Your second thread is in its own transaction, and should be loading all of its information from that transaction. By hitting user.UserID in the second thread, you're attempting to access database data from the original transaction which user is still associated with and concurrency related issues are occuring. Approaches to fix include: 1. The easiest way to do this is to keep all objects local to one thread. 2. Instead of passing user to the other thread, pass only user.UserID to the other thread. This keeps the access to user within its owning thread. 3. expunge() your User object from the thread in which it was created, and add() it to the Session corresponding to the other thread, before accessing user.UserID 4. merge() your User object to the Session corresponding to the other thread, where a copy of it will be created local to that Session (would have to see if merge() is smart enough to not load in expired attributes, though). 5. use mutexing to prevent concurrent access to the first Session (this may also necessitate not using ScopedSession depending on usage patterns). -- Regards, Harish --~--~-~--~~~---~--~~ 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: Fwd: Autoexpire on commit is causing problems?
Hello, Thanks for the fix. I downloaded latest changes r5060. The test I had done earlier is now going thru. But I am getting exceptions at other places : Traceback (most recent call last): File SchemaTest.py, line 206, in ? USERIDLIST.append(user.UserID) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\orm\attributes.py, line 135, in __get__ return self.impl.get(instance_state(instance)) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\orm\attributes.py, line 325, in get value = callable_() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\orm\attributes.py, line 892, in __call__ class_manager.deferred_scalar_loader(self, [ File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\orm\mapper.py, line 1698, in _load_scalar_attributes result = session.query(mapper)._get(identity_key, refresh_state=state, only_ load_props=attribute_names) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\orm\query.py, line 1181, in _get return q.all()[0] File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\orm\query.py, line 979, in all return list(self) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\orm\query.py, line 1044, in __iter__ return self._execute_and_instances(context) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\orm\query.py, line 1047, in _execute_and_instances result = self.session.execute(querycontext.statement, params=self._params, m apper=self._mapper_zero_or_none(), _state=self._refresh_state) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\orm\session.py, line 749, in execute return self.__connection(engine, close_with_result=True).execute( File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\engine\base.py, line 848, in execute return Connection.executors[c](self, object, multiparams, params) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\engine\base.py, line 899, in execute_clauseelement return self._execute_compiled(elem.compile(dialect=self.dialect, column_keys =keys, inline=len(params) 1), distilled_params=params) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\engine\base.py, line 908, in _execute_compiled context = self.__create_execution_context(compiled=compiled, parameters=dist illed_params) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\engine\base.py, line 952, in __create_execution_context return self.engine.dialect.create_execution_context(connection=self, **kwarg s) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\databases\sqlite.py, line 266, in create_execution_context return SQLiteExecutionContext(self, connection, **kwargs) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\engine\default.py, line 170, in __init__ self.cursor = self.create_cursor() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\engine\default.py, line 267, in create_cursor return self._connection.connection.cursor() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5060-py2.4.egg\s qlalchemy\engine\base.py, line 589, in connection raise exc.InvalidRequestError(This Connection is closed) sqlalchemy.exc.InvalidRequestError: This Connection is closed The line USERIDLIST.append(user.UserID),is trying to append the newly added (to the database) user object's primary key (UserID) into a List in one thread , to be used by another thread which tries to modify the object. Its throwing up exceptions there. This error will go away if I set expire_on_commit = False. Cheers, Harish On Fri, Aug 22, 2008 at 8:41 PM, Michael Bayer [EMAIL PROTECTED]wrote: The actual fix for this is in r5052. The ticket is not complete as tests have not yet been added but your test now passes. On Aug 22, 2008, at 5:51 AM, Harish K Vishwanath wrote: Further to below , if I do : u.id = 9 session.commit() 2008-08-22 15:16:54,066 INFO sqlalchemy.engine.base.Engine.0x..70 UPDATE users S ET id=? WHERE users.id = ? 2008-08-22 15:16:54,082 INFO sqlalchemy.engine.base.Engine.0x..70 [9, 8] 2008-08-22 15:16:54,082 INFO sqlalchemy.engine.base.Engine.0x..70 COMMIT u 2008-08-22 15:16:55,332 INFO sqlalchemy.engine.base.Engine.0x..70 BEGIN 2008-08-22 15:16:55,332 INFO sqlalchemy.engine.base.Engine.0x..70 SELECT users.i d AS users_id, users.name AS users_name FROM users WHERE users.id = ? 2008-08-22 15:16:55,332 INFO sqlalchemy.engine.base.Engine.0x..70 [9] User ID : 9, Name : One u.id = 11 session.commit
[sqlalchemy] Autoexpire on commit is causing problems?
Hello, I am SQLA 0.5beta4r5051. I am having issues with session having expire_on_commit as True. Below is an example : *File : sqla05betatest.py* from sqlalchemy import create_engine, Table, Column, Integer, String, MetaData from sqlalchemy.orm import mapper, sessionmaker engine = create_engine(sqlite:///:memory:,echo=True) class User(object): def __init__(self,name=anonymous): self.id = 0 self.name = name def __repr__(self): return User ID : %s, Name : %s % (repr(self.id),self.name) metadata = MetaData() usertable = Table('users',metadata, Column('id',Integer,primary_key=True), Column('name',String(50)) ) metadata.create_all(engine) mapper(User,usertable) Session = sessionmaker(bind=engine,autocommit=False,autoflush=False) #expireoncommit is True session = Session() Now using Python 2.4 interpreter : from sqla05betatest import * 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 PRAGMA table_i nfo(users) 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 {} 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 CREATE TABLE users ( id INTEGER NOT NULL, name VARCHAR(50), PRIMARY KEY (id) ) 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 {} 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 COMMIT u = User(One) session.add(u) session.commit() 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70 BEGIN 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70 INSERT INTO us ers (id, name) VALUES (?, ?) 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70 [0, 'One'] 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70 COMMIT u.id = 1 session.add(u) session.commit() 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70 BEGIN 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70 UPDATE users S ET id=? WHERE users.id = ? 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70 [1, 1] 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70 ROLLBACK Traceback (most recent call last): File stdin, line 1, in ? File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 663, in commit self.transaction.commit() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 375, in commit self._prepare_impl() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 359, in _prepare_impl self.session.flush() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 1351, in flush self._flush(objects) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 1419, in _flush flush_context.execute() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\unitofwork.py, line 265, in execute UOWExecutor().execute(self, tasks) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\unitofwork.py, line 757, in execute self.execute_save_steps(trans, task) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\unitofwork.py, line 772, in execute_save_steps self.save_objects(trans, task) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\unitofwork.py, line 763, in save_objects task.mapper._save_obj(task.polymorphic_tosave_objects, trans) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\mapper.py, line 1206, in _save_obj raise exc.ConcurrentModificationError(Updated rowcount %d does not match nu mber of objects updated %d % (rows, len(update))) sqlalchemy.orm.exc.ConcurrentModificationError: Updated rowcount 0 does not matc h number of objects updated 1 When I set u.id = 1, session.add(u), session.commit() , It should've issued an UPDATE sql updating id from '0' to '1'. But instead : 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70 UPDATE users S ET id=? WHERE users.id = ? 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70 [1, 1] Why is this? Now, If I use Flush instead of commit (but the session is autoflush = False, and autocommit=False) u.id = 1 session.add(u) session.flush() 2008-08-22 15:00:08,470 INFO sqlalchemy.engine.base.Engine.0x..70 UPDATE users S ET id=? WHERE users.id = ? 2008-08-22 15:00:08,470 INFO sqlalchemy.engine.base.Engine.0x..70 [1, 0] u.id = 2 session.add(u) session.flush() 2008-08-22 15:00:30,375 INFO sqlalchemy.engine.base.Engine.0x..70 UPDATE users S ET id=? WHERE users.id = ? 2008-08-22 15:00:30,375 INFO sqlalchemy.engine.base.Engine.0x..70 [2, 1] u.id = 3 session.add(u)
[sqlalchemy] Fwd: Autoexpire on commit is causing problems?
Further to below , if I do : u.id = 9 session.commit() 2008-08-22 15:16:54,066 INFO sqlalchemy.engine.base.Engine.0x..70 UPDATE users S ET id=? WHERE users.id = ? 2008-08-22 15:16:54,082 INFO sqlalchemy.engine.base.Engine.0x..70 [9, 8] 2008-08-22 15:16:54,082 INFO sqlalchemy.engine.base.Engine.0x..70 COMMIT u 2008-08-22 15:16:55,332 INFO sqlalchemy.engine.base.Engine.0x..70 BEGIN 2008-08-22 15:16:55,332 INFO sqlalchemy.engine.base.Engine.0x..70 SELECT users.i d AS users_id, users.name AS users_name FROM users WHERE users.id = ? 2008-08-22 15:16:55,332 INFO sqlalchemy.engine.base.Engine.0x..70 [9] User ID : 9, Name : One u.id = 11 session.commit() 2008-08-22 15:17:03,630 INFO sqlalchemy.engine.base.Engine.0x..70 UPDATE users S ET id=? WHERE users.id = ? 2008-08-22 15:17:03,630 INFO sqlalchemy.engine.base.Engine.0x..70 [11, 9] 2008-08-22 15:17:03,630 INFO sqlalchemy.engine.base.Engine.0x..70 COMMIT That is, before setting the id to a new value, if I just let the session do its query (since the object is expired after prev commit), there seems to be no problem in further commits. But as I mentioned in the below mail, using session.flush() without letting the session do its query seems to work. Does flush internally query and get the object before flushing it to DB which commit() doesn't seem to do? -- Forwarded message -- From: Harish K Vishwanath [EMAIL PROTECTED] Date: Fri, Aug 22, 2008 at 3:02 PM Subject: Autoexpire on commit is causing problems? To: sqlalchemy@googlegroups.com Hello, I am SQLA 0.5beta4r5051. I am having issues with session having expire_on_commit as True. Below is an example : *File : sqla05betatest.py* from sqlalchemy import create_engine, Table, Column, Integer, String, MetaData from sqlalchemy.orm import mapper, sessionmaker engine = create_engine(sqlite:///:memory:,echo=True) class User(object): def __init__(self,name=anonymous): self.id = 0 self.name = name def __repr__(self): return User ID : %s, Name : %s % (repr(self.id),self.name) metadata = MetaData() usertable = Table('users',metadata, Column('id',Integer,primary_key=True), Column('name',String(50)) ) metadata.create_all(engine) mapper(User,usertable) Session = sessionmaker(bind=engine,autocommit=False,autoflush=False) #expireoncommit is True session = Session() Now using Python 2.4 interpreter : from sqla05betatest import * 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 PRAGMA table_i nfo(users) 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 {} 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 CREATE TABLE users ( id INTEGER NOT NULL, name VARCHAR(50), PRIMARY KEY (id) ) 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 {} 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 COMMIT u = User(One) session.add(u) session.commit() 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70 BEGIN 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70 INSERT INTO us ers (id, name) VALUES (?, ?) 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70 [0, 'One'] 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70 COMMIT u.id = 1 session.add(u) session.commit() 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70 BEGIN 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70 UPDATE users S ET id=? WHERE users.id = ? 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70 [1, 1] 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70 ROLLBACK Traceback (most recent call last): File stdin, line 1, in ? File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 663, in commit self.transaction.commit() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 375, in commit self._prepare_impl() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 359, in _prepare_impl self.session.flush() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 1351, in flush self._flush(objects) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 1419, in _flush flush_context.execute() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\unitofwork.py, line 265, in execute UOWExecutor().execute(self, tasks) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\unitofwork.py, line 757, in execute self.execute_save_steps(trans, task) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\unitofwork.py, line 772
[sqlalchemy] Re: Code working on SQLA 0.4.6 is breaking on SQLA 0.5beta3
Hello Michael, Thanks for your input! I got the latest trunk from SVN. However, if my app specific baseclass is an old style class, it still breaks., this time in orm\attributes.py Traceback (most recent call last): File SqlDB_Test.py, line 9, in ? dbo = SqlDB(SqlDB_Test.Sqlite,c:\\testdbs) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 77, in __init_ _ self.initSetup(echo) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 115, in initSe tup elixir.setup_all(True) File d:\recogsys\src\python\rsiterm\__init__.py, line 145, in setup_all File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 816, in setup_entities File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 409, in setup_mapper File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\__init__.py, line 643, in mapper return Mapper(class_, local_table, *args, **params) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\mapper.py, line 197, in __init__ self.__compile_class() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\mapper.py, line 852, in __compile_class manager = attributes.create_manager_for_cls(self.class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1494, in create_manager_for_cls manager = factory(class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1047, in __init__ cls_state = manager_of_class(base) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1511, in manager_of_class finder = self.manager_finders[cls] File C:\Python24\lib\weakref.py, line 219, in __getitem__ return self.data[ref(key)] TypeError: cannot create weak reference to 'classobj' object This error goes away when I make my app baseclass as a new style class. It is not giving any problems with Exceptions class in Py2.4 though. Could this be a possible issue? On Wed, Aug 20, 2008 at 9:28 PM, Michael Bayer [EMAIL PROTECTED]wrote: On Aug 20, 2008, at 11:52 AM, Harish K Vishwanath wrote: Hello, Sorry if I am being stupid. I saw the ticket and r0535 and 537 changeset. Which version of SQLA incorporates these changesets? no worries...use the latest trunk, which will ultimately be released either as 0.5beta4 or 0.5.0. -- Regards, Harish --~--~-~--~~~---~--~~ 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] Could there be a behavioural difference in user defined DataTypes?
Hello, I have a class defining our own data type : class RsiSqliteDateTimeType(types.TypeEngine): def __init__(self): pass def get_col_spec(self): return VARCHAR(35) def convert_bind_param(self, value, engine): if value != None: return value.ToString() return None def convert_result_value(self, value, engine): if value != None: return dtime.CIRDateTime(value) return None CIRDateTime() is a custom written DateTime class. Now, a few of my test cases which would pass thru SQLA 0.4.6 is failing in SQLA 0.5beta4dev (latest trunk). It basically involves a lesser than comparision between CIRDateTime() object picked from SQLite database vs a newly passed CIRDateTime() object. in SQLA 0.4.6 : (CIRDateTime from Sqlite) CIRDateTime() #returns the current datetimestamp True in SQLA 0.5beta4 latest trunk : (CIRDateTime from Sqlite) CIRDateTime() #returns the current datetimestamp False I am still trying to find out why this anomaly is occuring. I went through the 0.5 migration guide, which talks about changes in the way milliseconds are stored on SQLITE, but this is my user defined data type. Could there be any difference between the two versions? -- Regards, Harish --~--~-~--~~~---~--~~ 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: Code working on SQLA 0.4.6 is breaking on SQLA 0.5beta3
Thanks Jason. Downloaded R5051, it works fine! Cheers, Harish On Thu, Aug 21, 2008 at 7:58 PM, jason kirtland [EMAIL PROTECTED] wrote: Thanks for the traceback. Give r5050 a try. Cheers, Jason Harish K Vishwanath wrote: Hello Michael, Thanks for your input! I got the latest trunk from SVN. However, if my app specific baseclass is an old style class, it still breaks., this time in orm\attributes.py Traceback (most recent call last): File SqlDB_Test.py, line 9, in ? dbo = SqlDB(SqlDB_Test.Sqlite,c:\\testdbs) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 77, in __init_ _ self.initSetup(echo) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 115, in initSe tup elixir.setup_all(True) File d:\recogsys\src\python\rsiterm\__init__.py, line 145, in setup_all File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 816, in setup_entities File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 409, in setup_mapper File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\__init__.py, line 643, in mapper return Mapper(class_, local_table, *args, **params) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\mapper.py, line 197, in __init__ self.__compile_class() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\mapper.py, line 852, in __compile_class manager = attributes.create_manager_for_cls(self.class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1494, in create_manager_for_cls manager = factory(class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1047, in __init__ cls_state = manager_of_class(base) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5048-py2.4.egg\s qlalchemy\orm\attributes.py, line 1511, in manager_of_class finder = self.manager_finders[cls] File C:\Python24\lib\weakref.py, line 219, in __getitem__ return self.data[ref(key)] TypeError: cannot create weak reference to 'classobj' object This error goes away when I make my app baseclass as a new style class. It is not giving any problems with Exceptions class in Py2.4 though. Could this be a possible issue? On Wed, Aug 20, 2008 at 9:28 PM, Michael Bayer [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: On Aug 20, 2008, at 11:52 AM, Harish K Vishwanath wrote: Hello, Sorry if I am being stupid. I saw the ticket and r0535 and 537 changeset. Which version of SQLA incorporates these changesets? no worries...use the latest trunk, which will ultimately be released either as 0.5beta4 or 0.5.0. http://0.5.0. -- Regards, Harish -- Regards, Harish --~--~-~--~~~---~--~~ 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] Facing Invalid Request Error in 0.5beta4r5051
Hello, I am getting a sa.exc.InvalidRequestError in SALA 0.5beta4, which never happened in SQLA 0.4.6 SQLA 0.4.6 : sqlalchemy.orm.sessionmaker(bind=None, autoflush=False, transactional=True) SQLA 0.5beta4 : sqlalchemy.orm.sessionmaker(bind=None, autoflush=False, autocommit=False) Apart from this, as per the documentation the SQLA 0.5 session is autoexpire=True, which expires all objects after a commit call. Below is the traceback of the exception : file:///E:/ChitradaChandrama/ File SchemaTest.py, line 193, in ? user = myDB.CreateTestUser(msg) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 633, in Create TestUser oiUser.SetAuthority('Authority', self) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlUser.py, line 154, in SetA uthority self.PostInteraction(rsiDB, 'Authority', str(val), targetUserID) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlUser.py, line 1056, in Pos tInteraction rsiDB.AddInteraction(iao) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 418, in AddInt eraction return interaction.InteractionID File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 135, in __get__ return self.impl.get(instance_state(instance)) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 319, in get value = callable_() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 877, in __call__ class_manager.deferred_scalar_loader(self, [ File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\mapper.py, line 1701, in _load_scalar_attributes result = session.query(mapper)._get(identity_key, refresh_state=state, only_ load_props=attribute_names) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1181, in _get return q.all()[0] File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 979, in all return list(self) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1044, in __iter__ return self._execute_and_instances(context) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1047, in _execute_and_instances result = self.session.execute(querycontext.statement, params=self._params, m apper=self._mapper_zero_or_none(), _state=self._refresh_state) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 744, in execute return self.__connection(engine, close_with_result=True).execute( File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 711, in __connection return self.transaction._connection_for_bind(engine) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 309, in _connection_for_bind self._assert_is_active() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 243, in _assert_is_active raise sa_exc.InvalidRequestError( sqlalchemy.exc.InvalidRequestError: The transaction is inactive due to a rollbac k in a subtransaction. Issue rollback() to cancel the transaction. The line rsiDB.AddInteraction(iao), calls a commit() after adding the object. In SQLA0.5beta4, the object which was attached to the session is expired after commit? The next statment which is trying to return object.id, is issuing another query but is getting an inactive transaction and hence the error. Correct? This doesn't happen in SQLA 0.4.6. How can I fix this error? Please note that I am handling all exceptions that can be raised by a commit() call , issuing a rollback and reporting them. But I dont seen any rollbacks at all, but even then the exception says so. Appreciate any inputs. Thanks, Harish --~--~-~--~~~---~--~~ 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: Facing Invalid Request Error in 0.5beta4r5051
The error goes away when I make the session expire_on_commit=False., But its a nice feature to have, how can I fix the exception below retaining this feature? -- Forwarded message -- From: Harish K Vishwanath [EMAIL PROTECTED] Date: Fri, Aug 22, 2008 at 11:04 AM Subject: Facing Invalid Request Error in 0.5beta4r5051 To: sqlalchemy@googlegroups.com Hello, I am getting a sa.exc.InvalidRequestError in SALA 0.5beta4, which never happened in SQLA 0.4.6 SQLA 0.4.6 : sqlalchemy.orm.sessionmaker(bind=None, autoflush=False, transactional=True) SQLA 0.5beta4 : sqlalchemy.orm.sessionmaker(bind=None, autoflush=False, autocommit=False) Apart from this, as per the documentation the SQLA 0.5 session is autoexpire=True, which expires all objects after a commit call. Below is the traceback of the exception : File SchemaTest.py, line 193, in ? user = myDB.CreateTestUser(msg) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 633, in Create TestUser oiUser.SetAuthority('Authority', self) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlUser.py, line 154, in SetA uthority self.PostInteraction(rsiDB, 'Authority', str(val), targetUserID) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlUser.py, line 1056, in Pos tInteraction rsiDB.AddInteraction(iao) File d:\recogsys\src\python\RSITerm\SQLConvert\SqlDB.py, line 418, in AddInt eraction return interaction.InteractionID File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 135, in __get__ return self.impl.get(instance_state(instance)) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 319, in get value = callable_() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\attributes.py, line 877, in __call__ class_manager.deferred_scalar_loader(self, [ File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\mapper.py, line 1701, in _load_scalar_attributes result = session.query(mapper)._get(identity_key, refresh_state=state, only_ load_props=attribute_names) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1181, in _get return q.all()[0] File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 979, in all return list(self) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1044, in __iter__ return self._execute_and_instances(context) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\query.py, line 1047, in _execute_and_instances result = self.session.execute(querycontext.statement, params=self._params, m apper=self._mapper_zero_or_none(), _state=self._refresh_state) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 744, in execute return self.__connection(engine, close_with_result=True).execute( File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 711, in __connection return self.transaction._connection_for_bind(engine) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 309, in _connection_for_bind self._assert_is_active() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051-py2.4.egg\s qlalchemy\orm\session.py, line 243, in _assert_is_active raise sa_exc.InvalidRequestError( sqlalchemy.exc.InvalidRequestError: The transaction is inactive due to a rollbac k in a subtransaction. Issue rollback() to cancel the transaction. The line rsiDB.AddInteraction(iao), calls a commit() after adding the object. In SQLA0.5beta4, the object which was attached to the session is expired after commit? The next statment which is trying to return object.id, is issuing another query but is getting an inactive transaction and hence the error. Correct? This doesn't happen in SQLA 0.4.6. How can I fix this error? Please note that I am handling all exceptions that can be raised by a commit() call , issuing a rollback and reporting them. But I dont seen any rollbacks at all, but even then the exception says so. Appreciate any inputs. Thanks, Harish -- Regards, Harish --~--~-~--~~~---~--~~ 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] Code working on SQLA 0.4.6 is breaking on SQLA 0.5beta3
Hello, I was using elixir 0.5.2 (SQL Alchemy 0.4.6) on Py 2.4. All my model objects inherits from Entity as well as another baseobject specific to our application. class User(elixir.Entity, application.baseobject): ... ... It used to work fine. Today I upgraded to SQLA 0.5 beta3 and elixir 0.6.1. The same code doesn't work anymore. File c:\Python24\lib\site- packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 816, in setup_entities File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 409, in setup_mapper File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqlalchemy \orm\__init__.py, line 623, in mapper return Mapper(class_, local_table, *args, **params) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqlalchemy \orm\mapper.py, line 196, in __init__ self.__compile_class() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqlalchemy \orm\mapper.py, line 844, in __compile_class manager = attributes.create_manager_for_cls(self.class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqlalchemy \orm\attributes.py, line 1498, in create_manager_for_cls existing_factories = collect_management_factories_for(class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqlalchemy \orm\attributes.py, line 1604, in collect_management_factories_for hierarchy = util.class_hierarchy(cls) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqlalchemy \util.py, line 408, in class_hierarchy for s in [_ for _ in c.__subclasses__() if _ not in hier]: AttributeError: class IRObject has no attribute '__subclasses__' IRObject is our app specific base class. Any ideas? Thanks, Harish --~--~-~--~~~---~--~~ 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: Code working on SQLA 0.4.6 is breaking on SQLA 0.5beta3
Hello, I changed my baseclass to Inherit from object and made it as a new class. Now it dies in trying to find hierarchy for built-in class exception.Exception. AttributeError: class Exception has no attribute '__subclasses__' In Py 2.5, Exceptions have been changed to new style classes, but it doesn't seem to be so in py 2.4. Is there a way to bypass this assumption of SA? Thanks, Harish On Wed, Aug 20, 2008 at 4:02 PM, [EMAIL PROTECTED] wrote: seems your baseclass is oldstyle class, not inheriting 'object'. python 2.5 newstyle classes (off object) has that __subclasses__() classmethod (see dir(type)), not sure if 2.4 has that at all. i've no idea where these are explained (as well as mro() and other type' stuff.) i looked a bit at the src and i have a may be related question: why, once a instrumentation (descriptor) is installed on some class X attribute xyz, the same descriptor has to be installed on all subclasses of it? getattr( some_subclass_of_X, 'xyz') would return it anyway? if it is to allow diff subclasses to have diff. instrumentation, why it has to be triggered by the base class and not by mapper? and if that is because the subclass may have no mapper... what it has to do with SA then? On Wednesday 20 August 2008 12:39:15 Harish K Vishwanath wrote: Hello, I was using elixir 0.5.2 (SQL Alchemy 0.4.6) on Py 2.4. All my model objects inherits from Entity as well as another baseobject specific to our application. class User(elixir.Entity, application.baseobject): ... ... It used to work fine. Today I upgraded to SQLA 0.5 beta3 and elixir 0.6.1. The same code doesn't work anymore. File c:\Python24\lib\site- packages\elixir-0.6.1-py2.4.egg\elixir\entity.py, line 816, in setup_entities File c:\Python24\lib\site-packages\elixir-0.6.1-py2.4.egg\elixir\entity .py, line 409, in setup_mapper File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqla lchemy \orm\__init__.py, line 623, in mapper return Mapper(class_, local_table, *args, **params) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqla lchemy \orm\mapper.py, line 196, in __init__ self.__compile_class() File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqla lchemy \orm\mapper.py, line 844, in __compile_class manager = attributes.create_manager_for_cls(self.class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqla lchemy \orm\attributes.py, line 1498, in create_manager_for_cls existing_factories = collect_management_factories_for(class_) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqla lchemy \orm\attributes.py, line 1604, in collect_management_factories_for hierarchy = util.class_hierarchy(cls) File c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta3-py2.4.egg\sqla lchemy \util.py, line 408, in class_hierarchy for s in [_ for _ in c.__subclasses__() if _ not in hier]: AttributeError: class IRObject has no attribute '__subclasses__' IRObject is our app specific base class. Any ideas? Thanks, Harish -- Regards, Harish --~--~-~--~~~---~--~~ 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: Code working on SQLA 0.4.6 is breaking on SQLA 0.5beta3
Hello, Sorry if I am being stupid. I saw the ticket and r0535 and 537 changeset. Which version of SQLA incorporates these changesets? On Wed, Aug 20, 2008 at 7:15 PM, Michael Bayer [EMAIL PROTECTED]wrote: On Aug 20, 2008, at 5:39 AM, Harish K Vishwanath wrote: Hello, I was using elixir 0.5.2 (SQL Alchemy 0.4.6) on Py 2.4. All my model objects inherits from Entity as well as another baseobject specific to our application. class User(elixir.Entity, application.baseobject): ... ... It used to work fine. Today I upgraded to SQLA 0.5 beta3 and elixir 0.6.1. The same code doesn't work anymore. when using SQLA betas, keep your eye on the SVN timeline. This issue is ticket 1078 and has been fixed in r5037. -- Regards, Harish --~--~-~--~~~---~--~~ 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] Query is checking for transaction status
Hi all, I am trying to do a count on a particular table : session.query(User).count() To get the number of User objects in the database. I am getting the exception below : return self.session.query( File c:\python24\lib\site-packages\SQLAlchemy-0.4.6-py2.4.egg \sqlalchemy\orm\ query.py, line 1075, in count return q._count() File c:\python24\lib\site-packages\SQLAlchemy-0.4.6-py2.4.egg \sqlalchemy\orm\ query.py, line 1084, in _count return self._col_aggregate(sql.literal_column('1'), sql.func.count, nested_c ols=list(self.mapper.primary_key)) File c:\python24\lib\site-packages\SQLAlchemy-0.4.6-py2.4.egg \sqlalchemy\orm\ query.py, line 1103, in _col_aggregate return self.session.scalar(s, params=self._params, mapper=self.mapper) File c:\python24\lib\site-packages\SQLAlchemy-0.4.6-py2.4.egg \sqlalchemy\orm\ session.py, line 632, in scalar return self.__connection(engine, close_with_result=True).scalar(clause, para ms or {}) File c:\python24\lib\site-packages\SQLAlchemy-0.4.6-py2.4.egg \sqlalchemy\orm\ session.py, line 597, in __connection return self.transaction.get_or_add(engine) File c:\python24\lib\site-packages\SQLAlchemy-0.4.6-py2.4.egg \sqlalchemy\orm\ session.py, line 199, in get_or_add self._assert_is_active() File c:\python24\lib\site-packages\SQLAlchemy-0.4.6-py2.4.egg \sqlalchemy\orm\ session.py, line 166, in _assert_is_active raise exceptions.InvalidRequestError(The transaction is inactive due to a r ollback in a subtransaction and should be closed) sqlalchemy.exceptions.InvalidRequestError: The transaction is inactive due to a rollback in a subtransaction and should be closed I am running this test in a multi threaded environment. Each of them has a separate session object. Two of the threads (one is the Main Thread itself) add users to the db, and the other two modify the objects added to the database. The Main Thread prints a reporting line after adding 50 objects which contains the info of how many User objects are there in the DB. The above query is executed in this context. The exception I get above is not consistent, that is, sometimes it comes after the first 50 records, sometimes after 200 and sometimes after 250. The session is transactional with autoflush=False. Why is a query trying to find out the status of session? Is there anything that could have been done wrong? Thanks in advance for the help! Cheers, Harish --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---