[sqlalchemy] before_flush event doesn't seem to permit additional update to dirty objects

2012-06-06 Thread Damian Dimmich
Hi, I have a before flush event set up that sets the current user_id and datetime on new objects that are going to be commited to the database (all tables have these fields). Unfortunately, it seems to ignore changes I make to existing objects, ie when I set the user_id (which i get from

[sqlalchemy] 'InstanceState' object has no attribute 'manager.mapper', w/ Jython2.7.2

2012-06-06 Thread Alexander Dorsk
Hello All, I was curious if anyone else has run into this error: error message Traceback (most recent call last): File util/sa/tests/test_sa_dao.py, line 96, in setUp self.session.add(tc1) File /home/adorsk/projects/gr/jenv2.7/Lib/site-packages/sqlalchemy/orm/session.py, line 1251, in

Re: [sqlalchemy] 'InstanceState' object has no attribute 'manager.mapper', w/ Jython2.7.2

2012-06-06 Thread Michael Bayer
unfortunately issues like these are often resulting from Jython bugs.For example, SQLAlchemy was entirely unusable with the previous version of Jython due to a bug in their __import__ mechanism. That the test works fine using regular cPYthon with psycopg2 further points to some

Re: [sqlalchemy] before_flush event doesn't seem to permit additional update to dirty objects

2012-06-06 Thread Michael Bayer
The code looks fine to me, other than the access of Session._new for which you should be really calling upon the public new collection. What you might want to make sure of is that the objects you expect to see in dirty are actually there. Sometimes objects don't make it into dirty until they

Re: [sqlalchemy] CircularDependencyError with relationships

2012-06-06 Thread Michael Bayer
you need to use the post_update option described at http://docs.sqlalchemy.org/en/rel_0_7/orm/relationships.html#rows-that-point-to-themselves-mutually-dependent-rows . On Jun 6, 2012, at 1:15 AM, Alex Grönholm wrote: I have trouble configuring two relationships from one class to another. The

[sqlalchemy] Re: 'InstanceState' object has no attribute 'manager.mapper', w/ Jython2.7.2

2012-06-06 Thread SA User
Ah, you're right, it does look like a Jython bug. When I run the code you provided above I get the error below, which does show that it's a Jython issue. Traceback (most recent call last): File t.py, line 13, in module print attrgetter(bar.bat)(f) AttributeError: 'Foo' object has no

Re: [sqlalchemy] CircularDependencyError with relationships

2012-06-06 Thread Alex Grönholm
06.06.2012 18:06, Michael Bayer kirjoitti: you need to use the post_update option described at http://docs.sqlalchemy.org/en/rel_0_7/orm/relationships.html#rows-that-point-to-themselves-mutually-dependent-rows . Thanks for the pointer. Problem solved :) On Jun 6, 2012, at 1:15 AM, Alex

[sqlalchemy] Re: before_flush event doesn't seem to permit additional update to dirty objects

2012-06-06 Thread Damian
Hello, Thanks for the response - how do I access the public new collection? In terms of the date not being updated - turns out that in my code the columns are called last_update_date and not last_updated which explains why it wasn't committing anything Also, for the Session.dirty objects I

[sqlalchemy] mapping without key

2012-06-06 Thread Victor Olex
With the understanding that we would loose the ability to properly track the sate of a mapped object and ability to update or insert in ORM and likely the ability to correctly use relationships as well - how can one accomplish a mapper, which would work on tables (views) without any key, which

[sqlalchemy] Declarative Models: Can they be used with two databases and two schema names?

2012-06-06 Thread Shawn Wheatley
Hi, I'm trying to use my declarative models to copy data from an Oracle database with a non-default schema name to a SQLite database (which has no schema name, or at least a default name that can't be changed). Copying from Oracle to Oracle has not been a problem for me, but Oracle to SQLite

Re: [sqlalchemy] mapping without key

2012-06-06 Thread Michael Bayer
There's two variants to this question, and I can't tell which one you're asking for. If the views in question do in fact have candidate keys, that is, columns which uniquely identify a row, you just specify those either to the Table or mapper() as the columns that uniquely identify the row.

Re: [sqlalchemy] Declarative Models: Can they be used with two databases and two schema names?

2012-06-06 Thread Michael Bayer
By far the easiest approach is to modify the username you're coming into Oracle as so that the schema in question is the default. Or if you can, create Oracle synonyms (i.e. CREATE SYNONYM) in the default schema that link to the schema-qualified tables. Otherwise SQLA doesn't have a lot of

Re: [sqlalchemy] Re: before_flush event doesn't seem to permit additional update to dirty objects

2012-06-06 Thread Michael Bayer
On Jun 6, 2012, at 1:48 PM, Damian wrote: Hello, Thanks for the response - how do I access the public new collection? it's called session.new In terms of the date not being updated - turns out that in my code the columns are called last_update_date and not last_updated which

[sqlalchemy] Re: mapping without key

2012-06-06 Thread Victor Olex
Thanks. Model that we work with has tables, which have no unique constraints. Keys can be inferred from data contained specified in ORM maping but there is no guarantee that this will always work because data may change. Still one could argue a case where mapping such table to a class has merit

[sqlalchemy] Re: mapping without key

2012-06-06 Thread Victor Olex
To be clear this is not a feature request. I could use a hit how to build a fake mapper like this if not compatible in certain cases. On Jun 6, 5:52 pm, Victor Olex victor.o...@vtenterprise.com wrote: Thanks. Model that we work with has tables, which have no unique constraints. Keys can be

[sqlalchemy] auto reflect to create table declarative table code

2012-06-06 Thread Benjamin Hitz
This seems (to me) like an obvious question but a brief googling and looking at the docs didn't seem to find the answer. I have an existing database (lets say mysql) I can easily create object like: class BroadPeaks(Base): __table__ = Table('broad_peaks', Base.metadata, autoload=True)

Re: [sqlalchemy] auto reflect to create table declarative table code

2012-06-06 Thread Michael Bayer
On Jun 6, 2012, at 7:47 PM, Benjamin Hitz wrote: This seems (to me) like an obvious question but a brief googling and looking at the docs didn't seem to find the answer. I have an existing database (lets say mysql) I can easily create object like: class BroadPeaks(Base): __table__

Re: [sqlalchemy] auto reflect to create table declarative table code

2012-06-06 Thread Benjamin Hitz
Nah, I don't want a simpler interface, I want something that just generates the code so I can extend it as needed. Ben On Jun 6, 2012, at 5:57 PM, Michael Bayer wrote: On Jun 6, 2012, at 7:47 PM, Benjamin Hitz wrote: This seems (to me) like an obvious question but a brief googling and