[sqlalchemy] echo_pool=True doesn't seem to have an effect

2012-07-09 Thread bojanb
Hi, I'm trying to debug some issues with sessions in my SQLAlchemy 0.7.4 application. However, setting echo_pool to True doesn't seem to log anything to standard output: db_engine=create_engine(DB_URI, echo_pool=True) Session = sessionmaker(bind=db_engine) Standard logging (echo=True) works

Re: [sqlalchemy] echo_pool=True doesn't seem to have an effect

2012-07-09 Thread bojanb
. echo_pool=True just shows major events like connection invalidations. On Jul 9, 2012, at 9:25 AM, bojanb wrote: Hi, I'm trying to debug some issues with sessions in my SQLAlchemy 0.7.4 application. However, setting echo_pool to True doesn't seem to log anything to standard output: db_engine

[sqlalchemy] Re: Mapping an object to multiple tables

2010-01-18 Thread bojanb
This can be done and it's not too complicated, but beware as in 95% of the time it's a deficency in your model; ie. you can refactor your model so that you don't need this. If it's the other 5% of cases, here's what the code looks like (I can't honestly remember if I read this in the docs or got

[sqlalchemy] Re: Column property vs. Python (class) property for calculated columns

2010-01-18 Thread bojanb
However, I have issues with the difference in NULL value semantics between Python and SQL. Ie. if a calculated column is defined via a column_property as price*amount, then the result will be NULL if any of the values is NULL. However, in Python, None*something throws a TypeError, so the

[sqlalchemy] Re: Column property vs. Python (class) property for calculated columns

2010-01-15 Thread bojanb
with a mix of Python properties and column_properties. On Jan 14, 4:23 pm, Michael Bayer mike...@zzzcomputing.com wrote: bojanb wrote: Let's say I want to have a simple calculated property in my class, eg. amount which is just qty * price. I can define it as a column_property in a mapper

[sqlalchemy] Column property vs. Python (class) property for calculated columns

2010-01-14 Thread bojanb
Let's say I want to have a simple calculated property in my class, eg. amount which is just qty * price. I can define it as a column_property in a mapper which makes it available in all database operations, eg. I can write session.query (myclass).filter_by(amount1000) which will create the

[sqlalchemy] Re: Identical column names in parent and child classes with joined-table inheritance

2009-11-17 Thread bojanb
This does it. One small drawback is that since the field is now defined as an attribute, one can't query on it (ie. session.query (class_).filter_by(modified_by='jack')), but we don't envison such a use case for this funcionality so it's OK for us. Recap of what was done: table columns were

[sqlalchemy] Query on a related object's field

2009-11-13 Thread bojanb
What is the easiest way of getting the equivalent of this: session.query(Someclass).filter_by(related_obj.field=somevalue) Ie. I want to filter by a field of an object that is in relation to objects of Someclass. My original idea was to add related_obj.field as a new relation in the mapper for

[sqlalchemy] Identical column names in parent and child classes with joined-table inheritance

2009-10-29 Thread bojanb
Hi, Can I have identical column names in both parent and child classes that are part of a joined-table inheritance? These are simply created, created_by, modified, modified_by columns that are populated by defaults defined for them (ie. default, server_default, onupdate). The values are written

[sqlalchemy] Re: A problem with SQLA'a referential integrity behavior, deferred constraints and PostgreSQL

2009-10-29 Thread bojanb
On Oct 29, 5:32 pm, Michael Bayer mike...@zzzcomputing.com wrote: how would the UOW honor RESTRICT ?  if you tell it to delete a parent, and you didn't tell it to delete a child, and you have a non-nullable FK or RESTRICT, you'd expect it tothrow an error, right ?   isn't that what

[sqlalchemy] Re: A problem with SQLA'a referential integrity behavior, deferred constraints and PostgreSQL

2009-10-29 Thread bojanb
Yes, the passive_deletes='all' solves this, the trick is to put it in the backref (I was putting it in the forward relation). On Oct 29, 8:29 pm, Michael Bayer mike...@zzzcomputing.com wrote: Michael Bayer wrote: bojanbwrote: On Oct 29, 5:32 pm, Michael Bayer mike...@zzzcomputing.com

[sqlalchemy] A problem with SQLA'a referential integrity behavior, deferred constraints and PostgreSQL

2009-10-26 Thread bojanb
I have columns in my database that logically shouldn't be null. However, I allow them to be null while the user is editing (creating) objects interactively. As this is done in a transaction, and values are checked before a commit, it's assured that nobody else ever sees invalid values and the

[sqlalchemy] Re: A problem with SQLA'a referential integrity behavior, deferred constraints and PostgreSQL

2009-10-26 Thread bojanb
explicitly in the application), but ondelete='RESTRICT' is not honored in such a setup. On Oct 26, 4:13 pm, Michael Bayer mike...@zzzcomputing.com wrote: bojanb wrote: I have columns in my database that logically shouldn't be null. However, I allow them to be null while the user is editing (creating

[sqlalchemy] Can I use MapperExtension.before_insert to prevent an object from being INSERTed on commit()?

2009-10-14 Thread bojanb
I was under the impression that returning EXT_STOP in my MapperExtension.before_insert() can prevent an object from being inserted into the database altogether, but that doesn't seem to be working, so I'm not sure if I'm misunderstanding the operation of MapperExtensions or it's a bug. I'd like

[sqlalchemy] Re: Can I use MapperExtension.before_insert to prevent an object from being INSERTed on commit()?

2009-10-14 Thread bojanb
it does not. http://www.sqlalchemy.org/docs/05/reference/orm/interfaces.html?highl... Returning EXT_STOP will halt processing of further extensions handling that method. that only refers to additional extensions. Right. The doc was a little ambigous - the or use the default functionality

[sqlalchemy] Re: Pre-commit validation spanning multiple tables/ORM classes

2009-09-22 Thread bojanb
My issue with SQLA validators is that they don't allow inconsistent state even on fields of a single object, which makes multi-field validation impossible. Eg. imagine you have fields tax_id and country_code on a customer object. For country code 'us', tax_id should be 9 digits long; for country

[sqlalchemy] Re: Pre-commit validation spanning multiple tables/ORM classes

2009-09-22 Thread bojanb
meaning, you set A.a and you can't depend on A.b being correct yet ?   Well sure.  How would you have it done ?  Something has to trigger the validate event at some point.     So if you need to wait for all of A.a, A.b, A.c, etc. to be setup first, then sure you'd throw your validation into

[sqlalchemy] Re: How to instantiate objects of a class mapped against multiple tables?

2009-09-17 Thread bojanb
the solution is the same as that I illustrated in a previous email, that when you map to a JOIN you must place all equivalent columns which you would like populated identically in groups.  This is described athttp://www.sqlalchemy.org/docs/05/mappers.html#mapping-a-class-agains... You're

[sqlalchemy] Re: How to instantiate objects of a class mapped against multiple tables?

2009-09-16 Thread bojanb
with_polymorphic can be set against any subset of classes, not just '*'. Yes, but in the first case I can't use with_polymorphic() on the query, because the query class is not the problem - I want the polymorphic load on an attribute (relation) of the queried class in order for the eagerload to

[sqlalchemy] Re: How to instantiate objects of a class mapped against multiple tables?

2009-09-16 Thread bojanb
I don't have the time most of today to get into it so I can't confirm what's going on.  Any chance you could map to a straight join of all four tables instead of a join to two sub-joins ? I tried the following join in the mapper for Subordinate: join(Employee, Person).join(Relation,

[sqlalchemy] Re: How to instantiate objects of a class mapped against multiple tables?

2009-09-15 Thread bojanb
The problem is when I have an object mapped against two tables, both of which are part of an inheritance hierarchy. I managed to synchronize the foreign key with the primary key (per the documentation link you provided). However, SQLAlchemy doesn't (or I can't instruct it how to) set the

[sqlalchemy] Re: How to instantiate objects of a class mapped against multiple tables?

2009-09-15 Thread bojanb
in the same way. On Sep 15, 4:32 pm, Michael Bayer mike...@zzzcomputing.com wrote: bojanb wrote: The problem is when I have an object mapped against two tables, both of which are part of an inheritance hierarchy. I managed to synchronize the foreign key with the primary key (per the documentation

[sqlalchemy] Re: How to instantiate objects of a class mapped against multiple tables?

2009-09-14 Thread bojanb
The root of the problem is inheritance. Let's say that I have a Person class and an Employee class that inherits from it. I also have a Meeting class that records meetings between two persons. A query on Meeting will always lazy load Employee's attributes, regardless of any lazy/eagerload

[sqlalchemy] Re: How to instantiate objects of a class mapped against multiple tables?

2009-09-14 Thread bojanb
still don't know how to instantiate objects of a class mapped against two tables when they contain both an autogenerated primary key from the first table and a mandatory foreign key from the second... On Sep 14, 4:31 pm, Michael Bayer mike...@zzzcomputing.com wrote: bojanb wrote: The root

[sqlalchemy] How to instantiate objects of a class mapped against multiple tables?

2009-09-11 Thread bojanb
Here's something I've been struggling with recently. I'll include the description of steps that got me here, as I believe the context will make the question clearer. It all started because I needed to show data (eg. in a list form) from two related tables (classes). However, SQLAlchemy would

[sqlalchemy] How to define 'count' as an SQL mapped attribute for many-to-many relationships?

2009-07-22 Thread bojanb
I'm not sure if this is a bug or I am just setting up the attribute wrong. Anyways, I'm having a problem defining count-type SQL mapped attribute in a situation with many-to-many relationships. The example here uses the classic book-author many-to-many relation. An author can have many books,

[sqlalchemy] A bug in SQL expression mapped attributes for inherited objects

2009-07-21 Thread bojanb
Hello, It took me a couple of days to narrow this down. It appears that when object inherits from another object via joined table inheritance (I haven't tested the other two inheritance modes), mapped attributes defined as SQL expressions don't load correctly. In the example below I have a