Re: [sqlalchemy]Close database connection in SQLAlchemy

2012-01-26 Thread Fayaz Yusuf Khan
On Sunday 22 Jan 2012 12:57:33 AM Sana wrote: • On page load im displaying data from the database each time the page is refreshed the query hits the database to retrieve the data there by taking long time for the page to load is thr any way by which the query hit the table oly for new

[sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Kent Bower
I think I understand why, during a flush(), if I use session.query().get() for an item that was just added during this flush, I don't get the persistent object I might expect because the session still has it as pending even though, logically, it is already persistent. I don't suppose you have

Re: [sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Michael Bayer
On Jan 26, 2012, at 11:28 AM, Kent Bower wrote: I think I understand why, during a flush(), if I use session.query().get() for an item that was just added during this flush, I don't get the persistent object I might expect because the session still has it as pending even though,

Re: [sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Kent
Fair enough. I had enough understanding of what must be going on to know flush isn't straightforward, but I'm still glad I asked. Sorry for having not read the documents very well and thanks for your answer, because from it, I surmise that before_flush() *is* safe for session operations,

Re: [sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Michael Bayer
yup, before_flush is made for that, and I've for some time had some vague plans to add some more helpers there so you could get events local to certain kinds of objects in certain kinds of states, meaning it would look a lot like before_update. But looping through .new, .dirty, and .deleted

Re: [sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Kent
So, as a typical example of where it seems very natural to use before_update, suppose you need to automatically update the not null sequence of a related table. This but to get the sequence you need to loop over the parent table's collection. You want the sequence to be human friendly

Re: [sqlalchemy] session.query().get() is unsupported during flush for getting an object that was just added?

2012-01-26 Thread Michael Bayer
On Jan 26, 2012, at 1:21 PM, Kent wrote: So, as a typical example of where it seems very natural to use before_update, suppose you need to automatically update the not null sequence of a related table. This but to get the sequence you need to loop over the parent table's collection.

[sqlalchemy] backrefs

2012-01-26 Thread Kent
Is there a straightforward way to determine if a RelationshipProperty has a corresponding reverse (backref)? -- 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

[sqlalchemy] Re: backrefs

2012-01-26 Thread Kent
I assume the non public property._reverse_property is just what I'm looking for. :) On Jan 26, 2:06 pm, Kent jkentbo...@gmail.com wrote: Is there a straightforward way to determine if a RelationshipProperty has a corresponding reverse (backref)? -- You received this message because you are

Re: [sqlalchemy] a list as a named argument for an in clause

2012-01-26 Thread Eric Rasmussen
Another possible approach is using the sql module to build the query: from sqlalchemy import sql ids = [1,2,3] query = sql.select([Table.col1, Table.col2], Table.id.in_(ids)) session.execute(query) I'm not sure how that fits into the larger context of what you're doing, but it's flexible and

[sqlalchemy] ArgumentError: Only update via a single table query is currently supported

2012-01-26 Thread Mason
Hi, I have some problem understanding this error. From googling around, this is about modifying data on more than 1 table, so the ORM wouldn't do it. However, my query is self.session.query(e).filter(e.src_id == src_id).filter(e.tar_id == tar_id).update({e.status: self._DELETE}) and it only

Re: [sqlalchemy] ArgumentError: Only update via a single table query is currently supported

2012-01-26 Thread Michael Bayer
On Jan 26, 2012, at 8:26 PM, Mason wrote: Hi, I have some problem understanding this error. From googling around, this is about modifying data on more than 1 table, so the ORM wouldn't do it. However, my query is self.session.query(e).filter(e.src_id == src_id).filter(e.tar_id ==