[sqlalchemy] how to access dirty/changed ORM attributes ?

2013-08-12 Thread Jonathan Vanasco
Is there a way to access the changed attributes of an ORM object ? Everything I've dug up refers to the dirty objects in a session, not the attributes of an object. ( I'm trying to automate some revision logging /auditing of sqlalchemy objects ) -- You received this message because you

Re: [sqlalchemy] how to access dirty/changed ORM attributes ?

2013-08-12 Thread Michael Bayer
http://docs.sqlalchemy.org/en/rel_0_8/orm/internals.html#sqlalchemy.orm.state.AttributeState On Aug 12, 2013, at 12:48 PM, Jonathan Vanasco jvana...@gmail.com wrote: Is there a way to access the changed attributes of an ORM object ? Everything I've dug up refers to the dirty objects in a

Re: [sqlalchemy] how to access dirty/changed ORM attributes ?

2013-08-12 Thread Jonathan Vanasco
there's a typo in the docs: bad: attr_state = insp.attr.some_attribute works: attr_state = insp.attrs.some_attribute -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an

Re: [sqlalchemy] Issue with session.expunge with mutually dependent tables

2013-08-12 Thread csdrane
Thanks Michael! On Sunday, August 11, 2013 4:33:20 PM UTC-4, Michael Bayer wrote: On Aug 11, 2013, at 3:06 PM, csd...@gmail.com javascript: wrote: I'm having problem with the following code which is designed to remove an object identified as malformed prior to session.commit(): if

Re: [sqlalchemy] how to access dirty/changed ORM attributes ?

2013-08-12 Thread Jonathan Vanasco
Thanks, Mike! That let me slap together a quick mixin class to store versioned data (of specific columns) in PostgreSQL - class RevisionObject(object): revision_columns = None revision_id = sa.Column(sa.Integer, nullable=False, default=0 ) revision_history = sa.Column(

[sqlalchemy] Code organization with declarative models

2013-08-12 Thread George Sakkis
Hello everyone, this is more of a code architecture and design question but I'm wondering what the best practices are regarding declarative models. On the one extreme, models are pretty barebone, with little more than the columns, relationships and possibly a few declared attributes and

Re: [sqlalchemy] Code organization with declarative models

2013-08-12 Thread AM
On 08/12/2013 02:50 PM, George Sakkis wrote: Hello everyone, this is more of a code architecture and design question but I'm wondering what the best practices are regarding declarative models. On the one extreme, models are pretty barebone, with little more than the columns, relationships

Re: [sqlalchemy] Code organization with declarative models

2013-08-12 Thread Jonathan Vanasco
Just for a bit of perspective... My SqlAlchemy integration for a project is connected to two distinct applications : - Pyramid -- Web Application - Celery -- Background Processing We're also hoping to get it working on a third - Twisted -- More Background Work There are a lot of moving parts

[sqlalchemy] Updating a one-to-many relationship

2013-08-12 Thread csdrane
I have another question about a piece of code that I posted the other day. Namely, I have a one-to-many relationship between Creator and Company. A Creator can have a relationship with multiple Companies but any one Company can have a relationship with only one Creator. class Company(Base):

Re: [sqlalchemy] Updating a one-to-many relationship

2013-08-12 Thread Tim Van Steenburgh
In `Company.__init__()`, instead of blindly creating a new `Creator` instance, you need to first query for an existing Creator with that name. If it exists, append it, otherwise, create a new one and append that. -- Tim Van Steenburgh On Monday, August 12, 2013 at 9:26 PM, csdr...@gmail.com

Re: [sqlalchemy] Updating a one-to-many relationship

2013-08-12 Thread csdrane
Sorry I don't understand what you're trying to say. If the Creator already exists, and I'm to append it again, isn't that the same as what my code is currently doing? (That is, appending in every instance.) I don't see how this wouldn't result in the same error message. And what would it mean

Re: [sqlalchemy] Updating a one-to-many relationship

2013-08-12 Thread Tim Van Steenburgh
It's not the append that's causing the error, it's the fact that you're creating a new Creator() instance, which ultimately results in an INSERT statement being issued. You want to append a Creator instance to `company.creator`, but you don't necessarily want to make a new Creator every time

Re: [sqlalchemy] Updating a one-to-many relationship

2013-08-12 Thread Tim Van Steenburgh
Sorry, that should have been: existing_creator = DBSession(Creator).query.filter_by(creator=creator).first() On Monday, August 12, 2013 at 9:49 PM, Tim Van Steenburgh wrote: It's not the append that's causing the error, it's the fact that you're creating a new Creator() instance, which

Re: [sqlalchemy] Updating a one-to-many relationship

2013-08-12 Thread Tim Van Steenburgh
Ad, one more try: existing_creator = DBSession.query(Creator).filter_by(name=creator).first() -- Tim Van Steenburgh On Monday, August 12, 2013 at 9:50 PM, Tim Van Steenburgh wrote: Sorry, that should have been: existing_creator =

Re: [sqlalchemy] Updating a one-to-many relationship

2013-08-12 Thread csdrane
Very helpful, thanks Tim :) On Monday, August 12, 2013 9:53:48 PM UTC-4, Tim wrote: Ad, one more try: existing_creator = DBSession.query(Creator).filter_by(name=creator).first() -- Tim Van Steenburgh On Monday, August 12, 2013 at 9:50 PM, Tim Van Steenburgh wrote: Sorry, that