[sqlalchemy] Problems filtering on primary_join with ORM relationship

2012-11-09 Thread Benjamin Sims
Hi, We have a relationship that looks something like this: User 1 - * Posts Posts can have various states, let's say 'DRAFT', 'LIVE', 'DELETED'. Sometimes, we want to get all of the posts in existence for a user by doing: user.all_posts Sometimes, we just want to get posts that are not

[sqlalchemy] Making an association proxy distinct

2012-05-01 Thread Benjamin Sims
Is there an obvious way to set up an association proxy so that it only returns distinct objects? For example, if I have: Post - Tag - Tag_Category and would like to access Post.Tag_Categories so that it contains each category only once. Any tips appreciated, sure I am missing something obvious

Re: [sqlalchemy] Making an association proxy distinct

2012-05-01 Thread Benjamin Sims
:08 AM, Benjamin Sims wrote: Is there an obvious way to set up an association proxy so that it only returns distinct objects? For example, if I have: Post - Tag - Tag_Category and would like to access Post.Tag_Categories so that it contains each category only once. Any tips

Re: [sqlalchemy] Debugging 'StatementError: Can't reconnect until invalid transaction is rolled back' error

2011-11-01 Thread Benjamin Sims
this I have to make sure that all DB calls do a session.close() or session.rollback() when finished? Any thoughts on how to track which call is leaving the connection open? On 31 October 2011 17:16, Michael Bayer mike...@zzzcomputing.com wrote: On Oct 31, 2011, at 12:56 PM, Benjamin Sims wrote

[sqlalchemy] Debugging 'StatementError: Can't reconnect until invalid transaction is rolled back' error

2011-10-31 Thread Benjamin Sims
Hi all, I'm seeing this error intermittently in my application since switching to MySQL - it occurs on several different pages and I can't track down why: StatementError: Can't reconnect until invalid transaction is rolled back (original cause: InvalidRequestError: Can't reconnect until invalid

Re: [sqlalchemy] Debugging 'StatementError: Can't reconnect until invalid transaction is rolled back' error

2011-10-31 Thread Benjamin Sims
the errors On 31 October 2011 14:38, Michael Bayer mike...@zzzcomputing.com wrote: On Oct 31, 2011, at 8:45 AM, Benjamin Sims wrote: Hi all, I'm seeing this error intermittently in my application since switching to MySQL - it occurs on several different pages and I can't track down why

[sqlalchemy] UnicodeEncodeError on saving to MySQL

2011-09-29 Thread Benjamin Sims
I've recently moved from SQLite to MySQL as the underlying database for my application. The move is causing me various problems, principally around Unicode. I *think* they were not occurring when SQLite was there, so I thought I would ask if anybody on the list has had similar problems. My

Re: [sqlalchemy] UnicodeEncodeError on saving to MySQL

2011-09-29 Thread Benjamin Sims
Bayer mike...@zzzcomputing.com wrote: Can you attach a traceback for that? Sent from my iPhone On Sep 29, 2011, at 7:45 AM, Benjamin Sims benjamins...@gmail.com wrote: I've recently moved from SQLite to MySQL as the underlying database for my application. The move is causing me various

Re: [sqlalchemy] Re: UnicodeEncodeError on saving to MySQL

2011-09-29 Thread Benjamin Sims
://farmdev.com/talks/unicode/ because it will help you understand what the dreaded error really means. On Sep 29, 9:06 am, Benjamin Sims benjamins...@gmail.com wrote: File scraper.py, line 77, in run session.commit() File /home/benjamin/test/test1/lib/python2.6/site-packages/SQLAlchemy

Re: [sqlalchemy] Bidirectional relationships with association proxies

2011-09-01 Thread Benjamin Sims
way - the side that does *not* have the foreign key on it).Since associations is on the backref side of the declaration here, use the backref() function and put cascade='all, delete-orphan' on that side. On Aug 31, 2011, at 7:04 AM, Benjamin Sims wrote: Hi, I'm still having troubles

[sqlalchemy] Bidirectional relationships with association proxies

2011-08-31 Thread Benjamin Sims
Hi, I'm still having troubles correctly figuring my various many-to-many relations. Originally, this was a 'standard' many-to-many; that is, a secondary table was specified. However, I now need to add further information to the relation and am converting into an AssociationObject. My problem is

[sqlalchemy] Cascade in many-to-many relationships: when orphans are not orphans

2011-08-25 Thread Benjamin Sims
Thanks for the help with my query the other day - as ever response was swift and bang on. I'm now trying to set up another m:n relationship in ORM correctly. Pseudocode: parentA.children.append(child1) parentA.children.append(child2) parentB.children.append(child2) session.delete(parentA) At

[sqlalchemy] Correct way to delete Association Objects

2011-08-24 Thread Benjamin Sims
I have a many-to-many relationship with attributes: Parent - AssocObject - Child I'm trying to set it up so that when an AssocObject is removed from parent, that instance of AssocObject and the Child are also deleted. So in my view I do: del parent.associatedobjects I have changed the model so

Re: [sqlalchemy] Integrity error when using association_proxy - one of the foreign keys is missing

2011-08-02 Thread Benjamin Sims
Thanks so much for the help. For the record, setting an __init__ argument on the association argument did the trick. Ben On 2 Aug 2011, at 01:47, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 1, 2011, at 8:34 PM, somewhatofftheway wrote: Hi, I'm trying to convert a