Re: [sqlalchemy] Looks like there is no event to catch "before" a rollback happens

2017-03-10 Thread Alessandro Molina
On Fri, Mar 10, 2017 at 3:40 PM, mike bayer wrote: > If this is truly, "unexpected error but we need to do things", perhaps you > can use before_flush() to memoize the details you need for a restore inside > of session.info. > > An event hook can be added but it would

[sqlalchemy] Looks like there is no event to catch "before" a rollback happens

2017-03-09 Thread Alessandro Molina
I have been looking for a way to know what's going to be rolled back in SQLAlchemy so that I can know what was changed and restore other database unrelated things to their previous state. By http://docs.sqlalchemy.org/en/latest/orm/events.html#session-events it looks like it's available an

[sqlalchemy] Lazy ForeignKey declaration

2014-01-13 Thread Alessandro Molina
Just noticed that SQLAlchemy 0.9 broke a LazyForeignKey class that was provided by TurboGears tgext.pluggable to make possible to declare foreign keys to models not yet defined at the time the ForeignKey was declared. The main use was something like: class User(DeclarativeBase):

Re: [sqlalchemy] Lazy ForeignKey declaration

2014-01-13 Thread Alessandro Molina
Looks good, just one curiosity, is there a reason for using after_parent_attach event instead of directly using _set_parent to register the LazyForeignKey for being resolved? 2014/1/13 Michael Bayer mike...@zzzcomputing.com On Jan 13, 2014, at 1:19 PM, Alessandro Molina alessandro.mol

Re: [sqlalchemy] subquery as column

2012-07-24 Thread Alessandro
Yes,I know, so simple... but it didn't work for me as far I didn't set the label for the internal select. I try it many times, but always without it; I didn't know it was mandatory. Thank you. first_id_row = s.query(Row.id_row).\ filter(Row.id_head ==

[sqlalchemy] subquery as column

2012-07-19 Thread Alessandro
with MySql. Thanks for your help Alessandro PS: I can get the same result with a different subquery, but I don't like it because it seems to me more complex: a subquery get the max_row_id and the min_row_id for each head_id, then I join it with HEAD, ROW as ROW_A and ROW as ROW_B and I get

[sqlalchemy] session query against more databases

2011-07-27 Thread Alessandro
).all() On internet I found old answers that say it is not possible, but it was the far 2007.. :-) Alessandro -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from

Re: [sqlalchemy] attaching an AttributeExt to an existing mapper

2011-02-07 Thread Alessandro Dentella
On Mon, Feb 07, 2011 at 10:26:18AM -0500, Michael Bayer wrote: Its easier to do in 0.7 where you just say event.listen(MyObject.attribute, append, fn), any time you want.Though we haven't implemented remove yet. I'd wait for the 0.7 betas if possible. nice!, but it's not an option to

Re: [sqlalchemy] attaching an AttributeExt to an existing mapper

2011-02-07 Thread Alessandro Dentella
On Mon, Feb 07, 2011 at 01:32:52PM -0500, Michael Bayer wrote: Otherwise you can append your AttributeExtension into the listeners collection on the attribute, I'd have to check the source of attributes.py to recall the exact name of the collection. a hint here would be appreciated.

[sqlalchemy] mapper for outerjoin: getting None objects

2010-10-31 Thread Alessandro Dentella
Hi, I have a join between 2 tables (User/Adresses, complete code below). I create a mapper as the join of the 2 classes as: m = orm.mapper(Join, User.__table__.outerjoin(Address.__table__) , properties = { 'j_id' : [Address.__table__.c.user_id,

Re: [sqlalchemy] .info dict on Column

2010-08-26 Thread Alessandro Dentella
On Tue, Aug 24, 2010 at 02:48:37PM -0400, Michael Bayer wrote: Info option is clearly very handy. At the moment I implemented an image field in sqlkit, (that's just a bunch of handler in the gui). In order to do that I used a type inherited with no addition, just to understand that that

[sqlalchemy] CircularDependencyError on 0.6 (works on 0.5.8)

2010-08-26 Thread Alessandro Dentella
Hi again, sorry for flooding with email this week... I stumbled on the CircularDependencyError in some occasions with self referencing models. I do understand that it can be tricky to INSERT and DELETE but I'm just updating rows. I reduced my problem to the bare minimum. It works both on 0.5.8

Re: [sqlalchemy] upgrading code with prop.backref from 0.5 - 0.6

2010-08-24 Thread Alessandro Dentella
On Sat, Aug 21, 2010 at 01:45:48PM -0400, Michael Bayer wrote: columns in a property column = prop.columns[0] props = [] for pr in mapper.iterate_properties: if isinstance(pr, properties.RelationProperty): if pr.direction.name in ('MANYTOONE',):

[sqlalchemy] session (autocommit/not autoflush) + begin dirty

2009-12-15 Thread Alessandro Dentella
Hi, I have been using session with autocommit=True and autoflush=False for a while now. I'm pretty happy with this but now I find something that I cannot understand: a session with dirty set full, after a begin() is empty, but no update is issued. How can that be possible? (And yes!

[sqlalchemy] Type of Column added with column_property

2009-12-15 Thread Alessandro Dentella
Hi, is there a way to set the type of a column added to a mapper with column_property? m = mapper(New, t, properties={ 'my_bool': column_property( func.my_bool(t.c.id, type=Boolean) ) }) func 'my_bool' is a stored procedure on Postgresql and

Re: [sqlalchemy] FlushError: instance is in unsaved, pending instance...

2009-12-09 Thread Alessandro Dentella
On Fri, Dec 04, 2009 at 02:52:37PM -0500, Michael Bayer wrote: On Dec 4, 2009, at 2:20 PM, Alessandro Dentella wrote: On Fri, Dec 04, 2009 at 01:27:46PM -0500, Michael Bayer wrote: On Dec 4, 2009, at 1:18 PM, Alessandro Dentella wrote: Is the only solution to attach an instance

[sqlalchemy] mapper for join, insert and reused instances

2009-12-09 Thread Alessandro Dentella
Hi, docs suggests (Mapping a Class against Multiple Tables) to build a mapper as this: class AddressUser(object): pass j = join(users_table, addresses_table) mapper(AddressUser, j, properties={ 'user_id': [users_table.c.user_id, addresses_table.c.user_id] })

Re: [sqlalchemy] FlushError: instance is in unsaved, pending instance...

2009-12-04 Thread Alessandro Dentella
Is the only solution to attach an instance (u.job = myjob) or is there another solution that doesn't require me to build the instance? if you want SQLA's delete-orphan capability, that's the only way. If you want to rely upon CASCADE rules in your DB to handle it instead, that's

Re: [sqlalchemy] FlushError: instance is in unsaved, pending instance...

2009-12-04 Thread Alessandro Dentella
On Fri, Dec 04, 2009 at 01:27:46PM -0500, Michael Bayer wrote: On Dec 4, 2009, at 1:18 PM, Alessandro Dentella wrote: Is the only solution to attach an instance (u.job = myjob) or is there another solution that doesn't require me to build the instance? if you want SQLA's delete

[sqlalchemy] FlushError: instance is in unsaved, pending instance...

2009-12-03 Thread Alessandro Dentella
Hi, I'm stuck with the code below raise FlushError complaining: Traceback (most recent call last): File stdin, line 49, in module File /misc/src/sqlalchemy/sqlalchemy/lib/sqlalchemy/orm/session.py, line 673, in commit self.transaction.commit() File

[sqlalchemy] Re: delete-orphan assigning fk. Related to FAQ 5.13

2009-07-27 Thread Alessandro Dentella
Movie is attached to a Director or not. like the FAQ says, we choose not to get into generating events from foreign keys being set. which is not a forever rule, but if you look in trac there are about 300 ORM issues open that I'd rather get resolved before I have the time to

[sqlalchemy] Re: Doubts on relation with cascade delete by backend

2009-07-25 Thread Alessandro Dentella
On Thu, Jul 23, 2009 at 02:48:12PM -0400, Michael Bayer wrote: add passive_deletes = True Thanks and sorry for the noise on such trivial question, present in the faq... , I've already used it and... forgot! sandro --~--~-~--~~~---~--~~ You received this

[sqlalchemy] delete-orphan assigning fk. Related to FAQ 5.13

2009-07-25 Thread Alessandro Dentella
In faq 5.13 it's explained why setting bar.foo_id would not generate the object bar.foo. I stumble in the same problem when creating a Movie in an example with Director/Movie and a relation -'movies' on director- that has 'delete-orphan'. running:: f = m.Movie(title=my title)

[sqlalchemy] delete-orphan assigning fk. Related to FAQ 5.13

2009-07-25 Thread Alessandro Dentella
[Sorry for reposting, Erroneously sent to another thread.] In faq 5.13 it's explained why setting bar.foo_id would not generate the object bar.foo. I stumble in the same problem when creating a Movie in an example with Director/Movie and a relation -'movies' on director- that has

[sqlalchemy] Re: session.autocommit, session.begin double SessionExtension call

2009-05-24 Thread Alessandro Dentella
On Sat, May 23, 2009 at 02:43:33PM -0400, Michael Bayer wrote: On May 23, 2009, at 10:15 AM, Alessandro Dentella wrote: Hi, when from my pygtk application i commit, I really do:: if self.session.autocommit: self.session.begin

[sqlalchemy] session.autocommit, session.begin double SessionExtension call

2009-05-23 Thread Alessandro Dentella
Hi, when from my pygtk application i commit, I really do:: if self.session.autocommit: self.session.begin() self.session.commit() I'm normally using session.autocommit = True as a mean to prevent all those 'idle in transaction' processes (that

[sqlalchemy] creating objects in after_flush hook

2009-05-12 Thread Alessandro Dentella
Hi, in a sessionExtension.after_flush hook I create objects (namely todo actions depending on what people have inserted/updated). At present I create these objects in the current session, but I do understand is not clean as the flush has already occurred. It almost works, objects are

[sqlalchemy] insert and joined mappers

2009-05-05 Thread Alessandro Dentella
Hi, how should I configure a mapper that represents a join between two tables so that inserting a new object writes the foreign key between the two in the proper way? class Table_a(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True)

[sqlalchemy] puzzling outerjoin in the mapper

2009-04-19 Thread Alessandro Dentella
Hi, i'm playing with outerjoin defined in the mapper. I'm getting results different from what I expected, so that I would like to understand which is the underline logic. Where a Query w/ outerjoin SELECT has in the backend n rows and would have m rows in a simple join, I only get m rows plus

[sqlalchemy] Attempting to flush an item of type...

2009-04-16 Thread Alessandro Dentella
Hi, I have a structure as this: fossati setup (module with attribute USER) models/cliente(User) calendar (Entry) apps/job in calendar.py: from cliente import User class Entry(Base): ... user = relation(User,

[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] session of an object

2009-03-25 Thread Alessandro Dentella
Hi, is there a way to get the session an object belongs to? I have been looking around and cannot find any function/way for that... Thanks in advance sandro *:-) -- Sandro Dentella *:-) http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy

[sqlalchemy] getting referenced *class* from relation

2009-03-16 Thread Alessandro Dentella
Hi, I'd like to get programmatically the class to which a relation points. Suppose I have the following situation: class Project(Base): ... staff = relation(User, secondary=project_manager) manager = relation(User, secondary=project_staff) Now I want to get User class

[sqlalchemy] commit, hooks and SessionExtension

2009-03-08 Thread Alessandro Dentella
Hi, i'm adding in sqlkit library some signals around commit, and particularly in post-commit phase. As I'd like to have the possibility to see which attributes where modified from within the callback I used 'after_flush' method of SessionExtension. So I have 2 questions: 1.

[sqlalchemy] Re: puzzling setup with ForeignKey - SOLVED

2009-02-20 Thread Alessandro Dentella
On Thu, Feb 19, 2009 at 12:57:07PM +0100, Alessandro Dentella wrote: Hi, in a working setup I added a ForeignKey to table 'cliente_cliente' as follows (client_id): class Project(Base): __tablename__ = ticket_project __table_args__ = {'useexisting' : True} id

[sqlalchemy] Re: (InterfaceError) connection already closed

2009-02-02 Thread Alessandro Dentella
On Sun, Feb 01, 2009 at 04:41:11PM -0500, Michael Bayer wrote: Here you go, its a psycopg2 bug. Familiarize yourself with the attached test case, then post it on the psycopg2 mailing list. Thanks a lot for you fast and valuable help, as usual. I verified that version 2.0.8 of psycopg2 does

[sqlalchemy] Re: (InterfaceError) connection already closed

2009-02-01 Thread Alessandro Dentella
stack trace you posted doesn't make sense to me though, as its issuing a SELECT statement but PG is raising an exception for an UPDATE / DELETE ? I've never seen that before. If you can provide a self- contained test case which reproduces that behavior we can try it out. Here is is.

[sqlalchemy] Re: (InterfaceError) connection already closed

2009-01-30 Thread Alessandro Dentella
connection already closed is a psycopg2 error indicating that the socket has been shut down. looking at your output, I see a raw execute() occuring within the string conversion of your Project object and theres a module called sqlkit/db/utils.py causing an exception throw. SQLA's

[sqlalchemy] Re: Autoloading float field from sqlite

2009-01-07 Thread Alessandro Dentella
On Wed, Jan 07, 2009 at 01:12:48PM -0500, Michael Trier wrote: Hi On Wed, Jan 7, 2009 at 9:35 AM, sandro dentella san...@e-den.it wrote: I realize now that autoloading a float field in Sqlite returns a SLNumeric rather that Float. The schema is: is this a known issue?

[sqlalchemy] Re: query doctest

2008-12-01 Thread Alessandro Dentella
in another place comparing str fails just because a join has ON join condition inverted (but semantically equivalent). What's the correct way to test if two queries are semantically equivalent? Thanks sandro *:-) Hi sandro, did you want to compare

[sqlalchemy] Re: flush session.is_modified()

2008-11-18 Thread Alessandro Dentella
On Tue, Nov 18, 2008 at 10:27:32AM -0500, Michael Bayer wrote: is_modified() shouldn't trigger a flush. is that with rc4 ? no it was svn rev. 4935. It's still the same with rev. 5311. I verified again: autoflush=False, just works. Autoflush=True shows that ## here session.new is not empty

[sqlalchemy] Re: flush session.is_modified()

2008-11-18 Thread Alessandro Dentella
On Tue, Nov 18, 2008 at 11:31:38AM -0500, Michael Bayer wrote: is_modified() has a flag passive which when set to True, disables lazy loaders from executing. As it turns out the flag was also not hooked up so you'd have to use the latest trunk to get this. the reason it wants to lazily

[sqlalchemy] Re: ClauseList with join?

2008-10-12 Thread Alessandro Dentella
On Sat, Oct 11, 2008 at 11:19:31PM -0400, Michael Bayer wrote: On Oct 11, 2008, at 1:44 PM, sandro dentella wrote: Hi, I started using the .join() method on query and that' s really powerful, with reset_joinpoint and the list of attributes setting the path of relations. Now

[sqlalchemy] Re: classes and mapper

2008-09-10 Thread Alessandro Dentella
Yep: m = sqlalchemy.orm.class_mapper(User) Thanks a lot! *:-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To