[sqlalchemy] SA remove related fields

2011-09-20 Thread Enrico Morelli
Dear all, I'm using SA 0.6.7 on a RHEL 6 with Python 2.6 and PostgreSQL 8.4.7. These are some table of my DB: pdb_table = Table('pdb', metadata, Column('id', types.Integer, primary_key=True), Column('code', types.Unicode(4), nullable=False), ) chain_table = Table('chain', metadata,

[sqlalchemy] safe delete recipe

2011-09-20 Thread Andrei Chirila
Hello, I'm working at implementing a safe delete on my models (having a deleted_at field which is checked and setting a deleted_at field when a model is deleted). I looked over the LimitingQuery recipe and at SessionEvents.before_flush and bellow is my solution. As I'm kind of new SqlAlchemy

Re: [sqlalchemy] SA remove related fields

2011-09-20 Thread Michael Bayer
On Sep 20, 2011, at 3:24 AM, Enrico Morelli wrote: Dear all, I'm using SA 0.6.7 on a RHEL 6 with Python 2.6 and PostgreSQL 8.4.7. These are some table of my DB: pdb_table = Table('pdb', metadata, Column('id', types.Integer, primary_key=True), Column('code', types.Unicode(4),

Re: [sqlalchemy] SA remove related fields

2011-09-20 Thread Enrico Morelli
On Tue, 20 Sep 2011 09:14:20 -0400 Michael Bayer mike...@zzzcomputing.com wrote: On Sep 20, 2011, at 3:24 AM, Enrico Morelli wrote: Dear all, I'm using SA 0.6.7 on a RHEL 6 with Python 2.6 and PostgreSQL 8.4.7. These are some table of my DB: pdb_table = Table('pdb', metadata,

Re: [sqlalchemy] SA remove related fields

2011-09-20 Thread Michael Bayer
On Sep 20, 2011, at 9:28 AM, Enrico Morelli wrote: Thanks, I tried to put passive_deletes='all' in the relationships: sorry, 'pdb':relationship(Pdb, backref=backref('metal', passive_deletes='all')) more docs that I'd recommend:

Re: [sqlalchemy] checking if some object with the given id is in a session

2011-09-20 Thread Michael Bayer
you can check for a given identity in the session using the identity key functions: from sqlalchemy.orm.util import identity_key key= identity_key(MyClass, someid) object_already_in_session = key in session.identity_map but usually people use session.merge(object) instead of session.add() to

Re: [sqlalchemy] safe delete recipe

2011-09-20 Thread Michael Bayer
On Sep 20, 2011, at 8:33 AM, Andrei Chirila wrote: Hello, I'm working at implementing a safe delete on my models (having a deleted_at field which is checked and setting a deleted_at field when a model is deleted). I looked over the LimitingQuery recipe and at SessionEvents.before_flush

Re: [sqlalchemy] safe delete recipe

2011-09-20 Thread Andrei Chirila
Hello Michael, Thank you :) I changed the code according to your indications: def paranoid_delete(session, flush_context, instances): Intercepts item deletions (single item deletions) and, if there is a field deleted_at for that object, it's updating deleted at instead of

Re: [sqlalchemy] safe delete recipe

2011-09-20 Thread Michael Bayer
On Sep 20, 2011, at 10:12 AM, Andrei Chirila wrote: Hello Michael, Thank you :) I changed the code according to your indications: def paranoid_delete(session, flush_context, instances): Intercepts item deletions (single item deletions) and, if there is a field deleted_at

Re: [sqlalchemy] SA remove related fields

2011-09-20 Thread Enrico Morelli
On Tue, 20 Sep 2011 09:32:09 -0400 Michael Bayer mike...@zzzcomputing.com wrote: On Sep 20, 2011, at 9:28 AM, Enrico Morelli wrote: Thanks, I tried to put passive_deletes='all' in the relationships: sorry, 'pdb':relationship(Pdb, backref=backref('metal', passive_deletes='all'))

Re: [sqlalchemy] Versioning and Foreign Keys

2011-09-20 Thread JPLaverdure
Hi Michael, Thanks for your reply... Your input is always very resourcefull, thanks ! I put together a small example which doesn't seem to function as expected: class Sample(Base): __metaclass__ = VersionedMeta __tablename__ = 'sample' __table_args__ = {'schema':'test'} id =

Re: [sqlalchemy] Versioning and Foreign Keys

2011-09-20 Thread Michael Bayer
On Sep 20, 2011, at 11:53 AM, JPLaverdure wrote: This fails because of the nullable=False clause on the Sample foreign key as SQLA seems to try to update the sample to set box_id to null... console printout: (from the delete portion) I'm not sure this has anything to do with versioning ?

Re: [sqlalchemy] Versioning and Foreign Keys

2011-09-20 Thread JPLaverdure
Oh god... I thought the statements used when declaring the ForeignKey (ondelete, onupdate) would imply that the relationship function in the same manner. I didn't think the 2 would be decoupled so much.. Although now that you point it out, it does seem consistent. I guess when I thought the

[sqlalchemy] Re: PyODBCConnector, possible wrong assumption re Unicode in bind parameters

2011-09-20 Thread Victor Olex
The ODBC on Linux has always been flaky but somehow I always managed to get it to work well enough. I don't have OSX to try but I could do some testing on more recent versions of Linux. What distro are you struggling with? I am not sure how else I can help. Time is short for most. On Sep 18, 3:42 

[sqlalchemy] ORM or Core

2011-09-20 Thread RedBaron
Hi, I am a newbie to SQLAlchemy. While reading the docs on the sqlalchemy site, I was a bit confused about ORM and Core. From what I understand, we can define table and class mapping either through ORM (defining a class that extends Base and so on) or we can directly use Core components (Define