[sqlalchemy] Another query on many to many relation

2009-04-08 Thread Marcin Krol
Hello, I have two classes: Host, Reservation (in many-to-many relation), and three tables: hosts, host_reservation (association table), reservation. I need to get table of pairs (host, reservation) *where host is unique and (reservation for this host that has the earliest date OR None in

[sqlalchemy] Many to Many using self-reference in Declarative

2009-04-08 Thread Scripper
Hi, for implementation of a many to many relationship i create a second plain table which contains two columns from the same user table: user_target_table = Table(user_target, metadata, Column('user_id', Integer, ForeignKey('tg_user.user_id')), Column('target_id', Integer,

[sqlalchemy] Re: Mapper with declarative

2009-04-08 Thread Scripper
get it! Problem solved! On 7 Apr., 19:16, J. Cliff Dyer j...@sdf.lonestar.org wrote: On Tue, 2009-04-07 at 06:28 -0700, Scripper wrote: Hello everyone, I have a concrete question about using declarative mapper in my project. When i there appeared some errors. I wonder whether

[sqlalchemy] Re: When to create new sessions?

2009-04-08 Thread Diez B. Roggisch
On Wednesday 08 April 2009 05:53:12 Michael Bayer wrote: On Apr 7, 2009, at 6:07 PM, rintin...@googlemail.com wrote: Hey Everyone, I'm new to SQLAlchemy (used to using Django's ORM but need to switch) and there's just one thing I'm struggling with, which is when am I supposed to create

[sqlalchemy] Re: 0.5.3 and mssql

2009-04-08 Thread Lukasz Szybalski
On Tue, Apr 7, 2009 at 2:58 PM, Lukasz Szybalski szybal...@gmail.com wrote: Hello, Is this still proper connection string for mssql where I specify the tds version and a connection driver name?  e =

[sqlalchemy] Relative speed of ORM vs. direct insertions (on simple tables)

2009-04-08 Thread Gregg Lind
Good morning! I hope I'm not tipping any sacred cows here, but for simple SqlA objects, it seems to be a heckuva lot faster to just insert into the table directly (using SqlA expression language) than to insert the objects via session.flush(). In the attached tests, I'm observing a 10x -20x

[sqlalchemy] Another query on many to many relation

2009-04-08 Thread Marcin Krol
Hello, P.S. Definitions: class Reservation(object): def __init__(self, startdate, enddate, status, bneed, nhwrep): self.start_date = startdate self.end_date = enddate self.status = status self.businessneed = bneed self.notetohwrep = nhwrep

[sqlalchemy] Re: Calling Oracle Stored Procedures Having Out Cursor Parameter

2009-04-08 Thread cbaron
On Apr 7, 10:49 pm, Michael Bayer mike...@zzzcomputing.com wrote: we have an outparam construct which makes use of cx_oracle's built in   API for this: result = testing.db.execute(text(begin   foo(:x_in, :x_out, :y_out, :z_out); end;,   bindparams=[bindparam('x_in', Numeric),

[sqlalchemy] Re: Relative speed of ORM vs. direct insertions (on simple tables)

2009-04-08 Thread Gregg Lind
Some followups: Python 2.4.3 on 64-bit linux. Timings are near identical in SA 0.5.2 and 0.5.3. On Apr 8, 9:57 am, Gregg Lind gregg.l...@gmail.com wrote: Good morning! I hope I'm not tipping any sacred cows here, but for simple SqlA objects, it seems to be a heckuva lot faster to just

[sqlalchemy] Association Object Pattern

2009-04-08 Thread Christiaan Putter
Hi guys, I've got a question regarding the association object pattern. Though perhaps it's not what I should be using... Let's say I've got a Parent class that I'd like to add tags with data to. class Parent(Base) id = Str # The association object class Tag(Base) parent_id = Str

[sqlalchemy] Re: Relative speed of ORM vs. direct insertions (on simple tables)

2009-04-08 Thread Michael Bayer
Gregg Lind wrote: Good morning! I hope I'm not tipping any sacred cows here, but for simple SqlA objects, it seems to be a heckuva lot faster to just insert into the table directly (using SqlA expression language) than to insert the objects via session.flush(). In the attached tests, I'm

[sqlalchemy] Re: Calling Oracle Stored Procedures Having Out Cursor Parameter

2009-04-08 Thread Michael Bayer
cbaron wrote: On Apr 7, 10:49 pm, Michael Bayer mike...@zzzcomputing.com wrote: we have an outparam construct which makes use of cx_oracle's built in   API for this: result = testing.db.execute(text(begin   foo(:x_in, :x_out, :y_out, :z_out); end;,   bindparams=[bindparam('x_in',

[sqlalchemy] availability of related obj

2009-04-08 Thread Alessandro Dentella
Hi, I have a definition similar to this:: class Ticket(Base): __tablename__ = 'ticket' id = Column(Integer, primary_key=True) assigned_to_id = Column(ForeignKey(User.id)) assigned_to = relation(User, primaryjoin = assigned_to_id == User.id,

[sqlalchemy] Re: availability of related obj

2009-04-08 Thread Michael Bayer
Alessandro Dentella wrote: Hi, I have a definition similar to this:: class Ticket(Base): __tablename__ = 'ticket' id = Column(Integer, primary_key=True) assigned_to_id = Column(ForeignKey(User.id)) assigned_to = relation(User, primaryjoin =

[sqlalchemy] Re: availability of related obj

2009-04-08 Thread Michael Bayer
Alessandro Dentella wrote: Hi, I have a definition similar to this:: class Ticket(Base): __tablename__ = 'ticket' id = Column(Integer, primary_key=True) assigned_to_id = Column(ForeignKey(User.id)) assigned_to = relation(User, primaryjoin =

[sqlalchemy] Re: availability of related obj

2009-04-08 Thread sandro dentella
as soon as Ticket is persistent within the flush, the ticket.assigned_to relation will be live and will lazy load when accessed. no commit is needed. mmh, in the following example, I can't use assigned_to within after_flush. Am I doing something wrong? from sqlalchemy.ext.declarative import

[sqlalchemy] Re: availability of related obj

2009-04-08 Thread sandro dentella
specifically the lazy loader will work in the after_flush_postexec() phase of the sessionextension. during after_flush(), the post-flush bookkeeping has not been establishsed yet on assigned_to_id, and the lazy loader always looks for the persisted version of the attribute. ok, this

[sqlalchemy] Re: Relative speed of ORM vs. direct insertions (on simple tables)

2009-04-08 Thread Gregg Lind
Thank you for the excellent and comprehensive answer! I didn't realize exactly how much work the session object does As per your advice, I have taken steps to reduce the size of my session object, and things run much more quickly now. On Wed, Apr 8, 2009 at 12:50 PM, Michael Bayer

[sqlalchemy] declarative and __table_args__ I must be missing something simple.

2009-04-08 Thread Wayne Witzel
I assume I am over looking some simple thing, but I just can't seem to find it. Thanks for the assist, I have palms open ready for face planting. Using a class and table with orm.mapper() class Child(object): pass child_table = Table('child', meta.metadata, Column('parent_id',

[sqlalchemy] table reflection: include_columns does not include a component of the primary key?

2009-04-08 Thread phrrn...@googlemail.com
I am trudging through the unit tests for the Sybase backend and found an interesting one in test_nonreflected_fk_raises in engine/ reflection.py. A couple of the drivers look like they skip over the column if it is not contained within table.c but go ahead and create the primary_key in any case!

[sqlalchemy] Re: declarative and __table_args__ I must be missing something simple.

2009-04-08 Thread Wayne Witzel
Yep, there it is. Stupidly simple. Dug up some old know working source that did and diff and grep later I found the cause. __table_args__ needs to be give a tuple with an empty dictionary, like so. __table_args__ = (ForeignKeyConstraint(['parent_id', 'parent_ref'], ['parent.id', 'parent.ref']),

[sqlalchemy] Re: table reflection: include_columns does not include a component of the primary key?

2009-04-08 Thread Michael Bayer
phrrn...@googlemail.com wrote: I am trudging through the unit tests for the Sybase backend and found an interesting one in test_nonreflected_fk_raises in engine/ reflection.py. A couple of the drivers look like they skip over the column if it is not contained within table.c but go ahead and

[sqlalchemy] My sqlalchemy.orm.identity.IdentityManagedState is leaking

2009-04-08 Thread Chris Lewis
Hi everyone! I have a threaded application which deals with a lot of records (it generates hundreds of thousands in an hour). I have a Database module that my program imports, and use scoped_session to make the session thread-safe. When a record is to be inserted, my program passes the object to

[sqlalchemy] Re: My sqlalchemy.orm.identity.IdentityManagedState is leaking

2009-04-08 Thread Gregg Lind
I believe you want session.expunge() or session.expunge_all(). GL On Wed, Apr 8, 2009 at 6:05 PM, Chris Lewis cfle...@gmail.com wrote: Hi everyone! I have a threaded application which deals with a lot of records (it generates hundreds of thousands in an hour). I have a Database module

[sqlalchemy] Re: My sqlalchemy.orm.identity.IdentityManagedState is leaking

2009-04-08 Thread Chris Lewis
Something I've realized is that all objects are cascading from a large one. There's a large staff object, which then has a collection of people objects which then have a collection of people statistics objects. This might well be the problem. If so, how can I tell SQLA to commit to the database

[sqlalchemy] Re: My sqlalchemy.orm.identity.IdentityManagedState is leaking

2009-04-08 Thread Chris Lewis
Hi Gregg, Changing the Session.remove() to an expunge_all doesn't have any effect, the growth continues. Chris On Apr 8, 4:10 pm, Gregg Lind gregg.l...@gmail.com wrote: I believe you want session.expunge() or session.expunge_all(). GL On Wed, Apr 8, 2009 at 6:05 PM, Chris  Lewis

[sqlalchemy] Re: My sqlalchemy.orm.identity.IdentityManagedState is leaking

2009-04-08 Thread Chris Lewis
Breakthrough: Using Gregg's expunge_all, then commenting out the addition to collections, SQLA is not leaking anymore. Inside my team object, I go in then create the people and their statistics, but I don't add the people to the team collection anymore. The links are never used again, but it's a

[sqlalchemy] relation that works in .48 but fails in .53

2009-04-08 Thread Bobby Impollonia
I am porting some code from SQLA .48 to .53 . I have a relation that works in .48, but not in .53. At the end of this post is a test program demonstrating the problem. The program works in .48 but fails in .53 trying to understand the child1_object relation . The error message says to add

[sqlalchemy] Re: relation that works in .48 but fails in .53

2009-04-08 Thread Michael Bayer
this is a side effect of declarative which I covered in my pycon tutorial. Child1.id is a map of both child1.id and parent.id, since they are mapped under the same name. you can see this if you say Child1.id.property.columns. the non-foreign key parent.id takes precedence. the easy solution

[sqlalchemy] Re: relation that works in .48 but fails in .53

2009-04-08 Thread Bobby Impollonia
Is there a video or slides from that pycon talk available online? I see the overview on the pycon site (http://us.pycon.org/2009/tutorials/schedule/2PM4/) and it looks very interesting. I looked more at what you said about the parent id column taking precedence and that does seem to be what

[sqlalchemy] Re: My sqlalchemy.orm.identity.IdentityManagedState is leaking

2009-04-08 Thread Chris Lewis
Inside my team object, I go in then create the people and their statistics, but I don't add the people to the team collection anymore. The links are never used again, but it's a many-to-many relationship (a person can be on several teams), so I thought I needed to do this in order to get

[sqlalchemy] Re: When to create new sessions?

2009-04-08 Thread Bobby Impollonia
Now the decorator swallows exceptions silently. You have to reraise the exception after rolling back like Michael did. I believe the correct form is: def transaction(f): def wrapper(*args, **kwargs): try: value = f(*args, **kwargs) except: