[sqlalchemy] unbound method execute() must be called with Session instance as first argument (got Select instance instead)

2009-08-11 Thread sector119
Hi all! Why I get unbound method execute() must be called with Session instance as first argument (got Select instance instead) with following code? from twisted.internet import reactor, task, threads from twisted.application import service from twisted.python import log from sqlalchemy import

[sqlalchemy] Re: unbound method execute() must be called with Session instance as first argument (got Select instance instead)

2009-08-11 Thread Michael Bayer
sector119 wrote: Hi all! Why I get unbound method execute() must be called with Session instance as first argument (got Select instance instead) with following code? from twisted.internet import reactor, task, threads from twisted.application import service from twisted.python import

[sqlalchemy] Adding new columns to a table

2009-08-11 Thread tom
Hello, my question is quite a basic one, but I couldn't find an answer, maybe because it's too basic. I have a table User and want to add a new Column('donated', Boolean). Then I initialize the database with metadata.create_all (self.database_engine) but in phpPgAdmin there are no changes.

[sqlalchemy] Re: Reentrant data population script using sql alchemy

2009-08-11 Thread Michael Bayer
gizli wrote: Thanks a lot Michael. The merge functionality is what I was looking for. This also exposed a flaw in our model I think. We keep using the auto-increment primary keys which would make merge() impossible to use in the scenario I was describing. Right? if you want to merge data

[sqlalchemy] Re: Reentrant data population script using sql alchemy

2009-08-11 Thread Michael Bayer
gizli wrote: Thanks a lot Michael. The merge functionality is what I was looking for. This also exposed a flaw in our model I think. We keep using the auto-increment primary keys which would make merge() impossible to use in the scenario I was describing. Right? autoincrement or not has

[sqlalchemy] Re: Updating database after after_insert()

2009-08-11 Thread grassoalvaro
I don't know why but now exception is: InvalidRequestError: Instance 'DBAccount at 0x134360d0' is not persisted On 11 Sie, 01:34, grassoalvaro grassoalv...@yahoo.com wrote: Hi, example from Pylons application, but i think that framework doesn't matter here:     class

[sqlalchemy] Re: Updating database after after_insert()

2009-08-11 Thread Michael Bayer
you can't do Session operations and commits inside of after_insert(). you're already in the session.flush() operation. I guess I have to make this clearer for every individual method in the docs. grassoalvaro wrote: I don't know why but now exception is: InvalidRequestError: Instance

[sqlalchemy] Re: Updating database after after_insert()

2009-08-11 Thread grassoalvaro
Hmm, but after_insert() is the best place where i can put this king logic (updating/inserting data in may places). So i can't use session operations inside of after_insert() at all? On 11 Sie, 18:35, Michael Bayer mike...@zzzcomputing.com wrote: you can't do Session operations and commits

[sqlalchemy] Re: Updating database after after_insert()

2009-08-11 Thread grassoalvaro
This is not exactly what i was looking for. I want to connect only one model with some kind of operations, not all session... On 11 Sie, 19:36, Michael Bayer mike...@zzzcomputing.com wrote: grassoalvaro wrote: Hmm, but after_insert() is the best place where i can put this king logic

[sqlalchemy] Re: Updating database after after_insert()

2009-08-11 Thread Michael Bayer
grassoalvaro wrote: This is not exactly what i was looking for. I want to connect only one model with some kind of operations, not all session... scan through Session.dirty etc. for the objects you want. if a new extension MapperExtension.before_flush() were added it would be working more

[sqlalchemy] Re: Updating database after after_insert()

2009-08-11 Thread grassoalvaro
Oh, that is a good idea and it's working. Thanks ;-) On 11 Sie, 20:12, Michael Bayer mike...@zzzcomputing.com wrote: grassoalvaro wrote: This is not exactly what i was looking for. I want to connect only one model with some kind of operations, not all session... scan through

[sqlalchemy] Re: Adding method to ORM mapped object

2009-08-11 Thread tom
From what I see, you forgot the self argument in the getRendered function definition. def getRendered(self): return '%s\n%s' % (self.title, self.content) On Aug 10, 5:00 am, Andreas andr...@flausch.at wrote: Arghh... I got it. The problem was that I wasn't querying through a session,

[sqlalchemy] how sum elements with filters

2009-08-11 Thread Doron Tal
Hi sqlalchemy, I'm a newbie to SA. I hope you could help me with the following problem. Say that I have: class Position(Base): __tablename__ = 'Position' id = Column('id', Integer, primary_key=True) position = Column('name', String) #center, guard etc' class Player(Base):

[sqlalchemy] Re: Adding new columns to a table

2009-08-11 Thread Michael Bayer
1. append_column() only raises that error if the Column() you're sticking there was already associated with some other table or selectable object. 2. you need ALTER TABLE. you can of course just say engine.execute(ALTER TABLE rest of statement). For more options, there is an FAQ entry here:

[sqlalchemy] Proper way to use case() in a filter()?

2009-08-11 Thread Randy Syring
I have a case(...) that looks right when I print it and am now trying to use it in a filter, something like: sess.query(User).select_from(join(...)).filter(case(...) == 1) But I get an error. When dissecting the parts, the problem is coming from the case(...) == 1 part. Can someone tell me

[sqlalchemy] Re: Adding new columns to a table

2009-08-11 Thread Nelson
I have virtually the same question. To put it another way I have an ORM mapped Table() in my Python code. There is a Column() in that table that is not yet in my Postgres database. How do I get that Column () into the database? I have tried table.append_column(col) but it's telling me this

[sqlalchemy] Re: Proper way to use case() in a filter()?

2009-08-11 Thread Mike Conley
Not much detail to tell what is wrong. Here is a contrived but working example based on one of my examples: ut = Table('user',meta, Column('uid',String,primary_key=True), Column('name',String) ) kt = Table('keywords',meta, Column('keyword',String,primary_key=True) ) ukt =