Re: [sqlalchemy] session.is_modified() returns false positives sometimes

2015-12-09 Thread Юрий Пайков
aintaining diverging copies of logic... Anyway, thanks for the clarification, you're awesome as always среда, 9 декабря 2015 г., 22:04:29 UTC+5 пользователь Michael Bayer написал: > > > > On 12/09/2015 02:07 AM, Юрий Пайков wrote: > > > > Ok, here is the test >

[sqlalchemy] session.is_modified() returns false positives sometimes

2015-12-08 Thread Юрий Пайков
I run a program which creates, fills and merges to DB a list of mapped objects. I need to know if a merge created a new instance in a database or if it updated previously existing one or if it did noop. When I know the instance is persistent, my goal is to figure out if it's going to be

Re: [sqlalchemy] session.is_modified() returns false positives sometimes

2015-12-08 Thread Юрий Пайков
Ok, here is the test code https://gist.github.com/ojomio/941d03b728a88d93d010 Apart from reproducing the (seeming) problem, it prints out "PASSIVE_NO_RESULT"(yes, you were right about the name) which is *in* committed_state вторник, 8 декабря 2015 г., 19:44:16 UTC+5 пользователь Michael Bayer

[sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Юрий Пайков
I based my code on the Michaeil Bayer's answer to this Stack Overflow question . I extended it a little so it takes into account NULLs and ARRAY for Postgresql. class values(FromClause): named_with_column = True

Re: [sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Юрий Пайков
The problem is - I can't wrap my head round using it... Could you direct me to same compiled clause which uses bindparams? Or perhaps maybe to some documentation on SQLA internals, because it is quite difficult to track the whole query compilation process for me четверг, 19 ноября 2015 г.,

Re: [sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Юрий Пайков
t; > well what is the ARRAY data you're passing into it? can you provide a > complete example? > > On 11/19/2015 02:04 PM, Юрий Пайков wrote: > > The problem is - I can't wrap my head round using it... Could you > > direct me to same compiled clause which uses bindpara

Re: [sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Юрий Пайков
it as is from some object/field and won't parse the resulting query for params any further... четверг, 19 ноября 2015 г., 19:43:39 UTC+5 пользователь Michael Bayer написал: > > > > On 11/19/2015 05:29 AM, Юрий Пайков wrote: > > I based my code on the Michaeil Bayer's an

[sqlalchemy] If path in joinedload() include self-referential relationship, should I alias() every table after that relation ?

2015-07-15 Thread Юрий Пайков
I have an example here https://gist.github.com/ojomio/aa5eca3bea03d21e00e8. This code issue exactly one query and load everything at one time What I am asking about is line https://gist.github.com/ojomio/aa5eca3bea03d21e00e8#file-gistfile1-py-L65 If I don not use alias *second_B* and simply

Re: [sqlalchemy] If path in joinedload() include self-referential relationship, should I alias() every table after that relation ?

2015-07-15 Thread Юрий Пайков
:42 AM, Юрий Пайков wrote: I have an example here https://gist.github.com/ojomio/aa5eca3bea03d21e00e8. This code issue exactly one query and load everything at one time What I am asking about is line https://gist.github.com/ojomio/aa5eca3bea03d21e00e8#file-gistfile1-py-L65 If I don

Re: [sqlalchemy] Preserve mapped entities after wrapping the query

2015-04-25 Thread Юрий Пайков
Michael, thank you for you reply, I expected you to mention from_self :) I know about it, it is a handy trick indeed But I deliberately don't use it, because this way I don't know how to mention a column which I want to filter on This is due to the fact, that it is calculated i.e. there is no

Re: [sqlalchemy] Preserve mapped entities after wrapping the query

2015-04-25 Thread Юрий Пайков
апреля 2015 г., 11:39:08 UTC+5 пользователь Юрий Пайков написал: Michael, thank you for you reply, I expected you to mention from_self :) I know about it, it is a handy trick indeed But I deliberately don't use it, because this way I don't know how to mention a column which I want to filter

[sqlalchemy] Preserving entity in a query after wrapping that query in additional select

2015-04-24 Thread Юрий Пайков
q = session.query(Recipe, func.avg(Recipe.field1).over(...)).join(...) I have a query which selects some mapped entity as well as other columns. I then refer to the name of that entity when working with the result of the query: for entry in q.all(): recipe=entry.Recipe Now, I want

[sqlalchemy] Is there a way to preserve entity after wrapping the Query in additional select?

2015-04-24 Thread Юрий Пайков
I have a query which selects an entity A and some calculated fields q = session.query(Recipe,func.avg(Recipe.somefield).join(.) I then use what I select in a way which assumes I can subscript result with Recipe string: for entry in q.all(): recipe=entry.Recipe # Access KeyedTuple by

[sqlalchemy] SQLAlchemy's merge doesn't fill foreign keys with ids of new objects in relationship

2015-04-14 Thread Юрий Пайков
My question is when I have in a session a newly created object(doesn't have primary key yet, but will obtain it upon flush) and I merge to that session another object referring to the first one by relationship (*b* in the example) SQLAlchemy doesn't populate latter object with the primary key

Re: [sqlalchemy] SQLAlchemy's merge doesn't fill foreign keys with ids of new objects in relationship

2015-04-14 Thread Юрий Пайков
Oh, it seems that merge() actually does populate the b_id if that B is non-conflicting... Seems I have another problem . Thank you anyway, Michael вторник, 14 апреля 2015 г., 20:08:04 UTC+5 пользователь Michael Bayer написал: that's not what I see happening here. I see very simply that

Re: [sqlalchemy] Is it possible to populate relationship's collection with only query-filtered results using contains_eager()?

2015-02-01 Thread Юрий Пайков
Well, I added echo=True and saw the queries - no additional were made. Then I added populate_existing() and out of the blue I started to get the desired result, but frankly I don't quite understand why. What side-effects this could bring? суббота, 31 января 2015 г., 21:22:08 UTC+5

Re: [sqlalchemy] Is it possible to populate relationship's collection with only query-filtered results using contains_eager()?

2015-02-01 Thread Юрий Пайков
Thanks Michael for your attention! понедельник, 2 февраля 2015 г., 2:56:51 UTC+5 пользователь Michael Bayer написал: Юрий Пайков dia...@cry5tal.in javascript: wrote: Well, I added echo=True and saw the queries - no additional were made. Then I added populate_existing

[sqlalchemy] Is it possible to populate relationship's collection with only query-filtered results using contains_eager()?

2015-01-31 Thread Юрий Пайков
When I do a query like this result = session.query(A).\ join(A.bs).\ join(B.cs).\ filter_by(C.somedata.in_([4455, 4466])).\ options(contains_eager(A.bs).contains_eager(B.cs)).one() and list related C objects for b in result.bs: b.cs I get all related to B C objects instead of only those