Re: [sqlalchemy] Modifying a cascaded object directly and then saving its parent

2014-04-04 Thread Joril
Thanks for the very detailed explanation :) I think I'll tweak the application flow to avoid this kind of thing altogether... Many thanks again! -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving

[sqlalchemy] Modifying a cascaded object directly and then saving its parent

2014-04-03 Thread Joril
and save par.children = [child_reloaded] session.add(par) I tested this on SQLalchemy 0.9.4: Traceback (most recent call last): File testsa.py, line 44, in module session.add(par) File /home/joril/src/newprg/branches/sqla09/sqlalchemy/orm/session.py, line 1478, in add self

Re: [sqlalchemy] Using value from main query inside subquery

2013-04-26 Thread Joril
On Friday, April 26, 2013 12:25:42 AM UTC+2, Michael Bayer wrote: this will work out of the box in 0.8 as auto-correlation has been improved a lot. in 0.7 you can add correlate() explicitly: Nice, many thanks :) -- You received this message because you are subscribed to the Google

[sqlalchemy] Using value from main query inside subquery

2013-04-25 Thread Joril
Hi everyone! I have this working query: select * from A join B on A.id = B.a_id where exists (select 1 from C where A.id = C.a_id and C.value B.value) and I tried to implement it like this: q = Session.query(entities.A) q = q.join((entities.B, entities.A.id == entities.B.a_id)) q =

[sqlalchemy] Two-phase commit from different sessions

2012-01-30 Thread Joril
Hi everyone! I'm trying to do a two-phase commit using SQLalchemy 0.6.8 with Postgresql 8.3.4, but I think I'm missing something... The workflow goes like this: session = sessionmaker(engine)(autocommit=True) tx = session.connection().begin_twophase(xid) # Doesn't issue any SQL session.begin() #

[sqlalchemy] Re: Two-phase commit from different sessions

2012-01-30 Thread Joril
On Jan 30, 5:02 pm, Michael Bayer mike...@zzzcomputing.com wrote: What's happening above is the session is not in a transaction due to autocommit, so when you call session.connection(), that connection is thrown away as far as the Session is concerned.   If you wanted to do it the external

Re: [sqlalchemy] How to refer to a live SA transaction from subsequent requests

2012-01-25 Thread Joril
An entirely new database connection can resume this transaction by again calling BEGIN PREPARED with the same XID. I'm sorry, but I can't find this command inside the Postgresql docs... Am I missing something? I'm trying to do a multi-request two-phase transaction too, so I thought I

Re: [sqlalchemy] How to refer to a live SA transaction from subsequent requests

2012-01-25 Thread Joril
So I guess the idea is that each web request does a new PREPARE TRANSACTION with a unique xid, then when the results of all those requests are ready to be committed, the final call then calls COMMIT PREPARED on the full list of xids. I see... Many thanks for your timely explanation :)

[sqlalchemy] Filtered backref

2011-06-08 Thread Joril
Hi everyone! Is it possible to have a many-to-one declarative relation between two classes and a _filtered_ backref? I'm trying to build a tagging system for my bloglike application, and to allow a user to apply private tags to posts of other people. My classes are: Owner Post TagAssociation Tag

[sqlalchemy] Re: Strange lazy-load query

2011-03-08 Thread Joril
On 7 Mar, 15:55, Michael Bayer mike...@zzzcomputing.com wrote: the left outer join means there is a lazy=False or lazy='joinedload' on the relationship, or in this case since its sporadic, the parent Invoice is likely being loaded with an option like joinedload(Product.vat).    The options

[sqlalchemy] Strange lazy-load query

2011-03-07 Thread Joril
Hi everyone! I have an object graph like this: Invoice - Detail (one-to-many with cascade) - Product (many-to-one) - VAT (many-to-one) My problem is that sometimes if I have a Detail and try to read its Product, the triggered lazy-loading generates a query more complicated than necessary,

[sqlalchemy] DetachedInstanceError on assignment

2011-02-11 Thread Joril
Hi everyone! I have a client-server application that communicates like this: the client asks for something, the server fetches the data using SQLAlchemy, serializes it and sends it back to the client. Now the client can modify the data and send it back to the server for persistence. It works

[sqlalchemy] Re: Error closing cursor on MySQL silently traps exception

2011-01-23 Thread Joril
On Jan 22, 7:01 pm, Michael Bayer mike...@zzzcomputing.com wrote: Assuming the above raises its error just fine as it does on my system, there must be some unusual pattern in the way the error is being generated.    I don't know that there's anything on the  SQLAlchemy side that can address

[sqlalchemy] Error closing cursor on MySQL silently traps exception

2011-01-22 Thread Joril
Hi everyone! I'm building a Pylons webapp using SA 0.6.4 and MySQL-Python 1.2.3. Right now I'm writing the first change script for sqlalchemy-migrate (just 3 lines of SQL). I noticed that if the change script contains some syntax error, SA catches the exception (in pool.py) and logs a Error

[sqlalchemy] Re: Removing an element from an uncascaded many-to-many

2010-11-18 Thread Joril
On 17 Nov, 21:41, Michael Bayer mike...@zzzcomputing.com wrote: I'll also make the comment that while the pattern you're illustrating is very unusual (cascade turned off, re-adding detached objects), the ORM is not being consistent in its treatment of non-included child items in mutated

[sqlalchemy] Removing an element from an uncascaded many-to-many

2010-11-17 Thread Joril
Hi everyone! I'm puzzled by a behaviour shown by SA 0.6.5 that 0.5.8 didn't show, and I'm wondering what I'm doing wrong.. I have a simple uncascaded many-to-many relationship, and if I try the following: 1) save a child 2) close the session 3) associate the child to a parent and save the parent

[sqlalchemy] Re: version_id_col and custom DeclarativeMeta with 0.6

2010-11-16 Thread Joril
On 15 Nov, 18:57, Michael Bayer mike...@zzzcomputing.com wrote: First off, I can't reproduce your issue: Found the culprit: I had a stray 0.5.8 directory lying around, and of course it was being picked up.. T_T Sorry :( Second, if you want to switch to newer declarative features, just stick

[sqlalchemy] version_id_col and custom DeclarativeMeta with 0.6

2010-11-15 Thread Joril
Hi everyone! I'm trying to port my application from SA 0.5.8 to 0.6.5, and I'm having a problem with __mapper_args__.. :/ The application uses the declarative plugin, and every class derives from a customized declarative base that aims to add to each one the version_id_col. Right now the code is

[sqlalchemy] Understanding CircularDependencyError

2009-11-12 Thread Joril
Hi everyone! I'm using the Declarative plugin to generate/handle a DB of about 50 entities, with every kind of relation between them. I've just added a simple one-to-many relation, and now SA is complaining that: sqlalchemy.exc.CircularDependencyError: Circular dependency detected [(base_files,

[sqlalchemy] Re: Understanding CircularDependencyError

2009-11-12 Thread Joril
It looks like I should tinker with the use_alter parameter.. :) --~--~-~--~~~---~--~~ 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

[sqlalchemy] Re: Shallow copying

2009-10-26 Thread Joril
On 23 Ott, 19:19, Mike Conley mconl...@gmail.com wrote: I'm trying to automatically build a shallow copy of a SA-mapped object.. At the moment my function is just: newobj = src.__class__() for prop in class_mapper(src.__class__).iterate_properties:    setattr(newobj, prop.key,

[sqlalchemy] Re: Shallow copying

2009-10-26 Thread Joril
On 26 Ott, 13:41, Mike Conley mconl...@gmail.com wrote: I see, but I need a proper shallow copy instead, with every attribute.. Is there no way? :/ What is missed? I am not sure what you mean by shallow copy. The fact that there are relations to be lazy loaded is present in the new

[sqlalchemy] Re: Shallow copying

2009-10-26 Thread Joril
On 26 Ott, 15:29, Mike Conley mconl...@gmail.com wrote: So, in Python a non-automatic shallow copy would be: A = Some_class() A.refs = [B, C] Acopy = Some_class() Acopy.refs = A.refs My problem is that if A.refs has to be lazy loaded, when I try to copy it over to Acopy, it

[sqlalchemy] Re: UniqueConstraint with a function

2009-10-05 Thread Joril
In the end I followed the suggestion at http://stackoverflow.com/questions/1510018/compound-uniqueconstraint-with-a-function Many thanks for chiming in all the same :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

[sqlalchemy] UniqueConstraint with a function

2009-10-02 Thread Joril
Hi everyone! I have a class Document with attributes Number and Date, is there a way to set a UniqueConstraint on Number + year(Date)? (SQLAlchemy 0.5.5, PostgreSQL 8.3.4) Thanks in advance! --~--~-~--~~~---~--~~ You received this message because you are

[sqlalchemy] Re: UniqueConstraint with a function

2009-10-02 Thread Joril
On 2 Ott, 10:42, Joril jor...@gmail.com wrote: I have a class Document with attributes Number and Date, is there a way to set a UniqueConstraint on Number + year(Date)? Self-followup: should I use a unique Index instead? But how do you create a functional index in SQLAlchemy

[sqlalchemy] Auto-incrementing attribute with custom logic

2009-06-24 Thread Joril
Hi everyone! I have a simple Invoices class with a Number attribute that has to be filled in by the application when the user saves an invoice. There are some constraints: 1) the application is a (thin) client-server one, so whatever determines the number must look out for collisions 2) Invoices

[sqlalchemy] Re: Auto-incrementing attribute with custom logic

2009-06-24 Thread Joril
On 24 Giu, 16:28, Michael Bayer mike...@zzzcomputing.com wrote: whats the second question ?   is this expected? yes.  TypeEngine objects don't have anything to do with default value generation. I see, thanks! --~--~-~--~~~---~--~~ You received this message

[sqlalchemy] Re: Automatic eager loading

2009-05-19 Thread Joril
On 19 Mag, 01:03, Michael Bayer mike...@zzzcomputing.com wrote: you'd have to roll that yourself.  Its generally not feasable for   every relation on an object to be eagerloaded since it would create   too many joins. I see, I'll just choose eager loads manually depending on context then,

[sqlalchemy] SQLAlchemy-announce RSS

2009-05-02 Thread Joril
Hi everyone, I'm sorry, is there an RSS feed somewhere with just the announcements of SA's new releases? Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to

[sqlalchemy] Query with outer join and function

2009-04-10 Thread Joril
Hi everyone! I'm trying to concoct a somewhat complicated query via Query API.. The situation is the following: - A many-to-one relation between classes C and D - Class C has an attribute value My objective is to retrieve the ids of a left outer join between D and C (so, all the Ds and

[sqlalchemy] Re: Query with outer join and function

2009-04-10 Thread Joril
On 10 Apr, 12:52, a...@svilendobrev.com wrote: that's what i have in bitemporal queries. u need a groupby and subquery/ies. I see, thanks for your hint! I tried to do it with bare SQL via pgadmin, and I ended up with select d.id, c.id from d left outer join ( select c.* from c join (

[sqlalchemy] Re: Query with outer join and function

2009-04-10 Thread Joril
On 10 Apr, 15:43, Mike Conley mconl...@gmail.com wrote: Try this, has one nested query sub = session.query(C.id.label('c_id'),         C.d_id.label('d_id'),         func.max(C.value).label('c_maxvalue')         ).group_by(C.d_id).subquery() I tried something like that earlier, but

[sqlalchemy] Re: Query with outer join and function

2009-04-10 Thread Joril
On 10 Apr, 15:54, Mike Conley mconl...@gmail.com wrote: This will teach me to run a test it first, I don't think this is exactly right, but it should be close. That's ok all the same, thanks for taking the time for posting :) Anyway my current implementation via Query API is sub =

[sqlalchemy] Re: Query with outer join and function

2009-04-10 Thread Joril
On 10 Apr, 16:24, Joril jor...@gmail.com wrote: Now let's see if I can fetch complete instances of C instead of just the id X-) For the record, my final implementation: sub = s.query(C.d_id, func.max(C.value).label(v)). group_by(C.d_id).subquery() sub2 = s.query(C).join((sub

[sqlalchemy] Re: Getting relation orphans

2009-03-27 Thread Joril
On 26 Mar, 18:02, Michael Bayer mike...@zzzcomputing.com wrote: you can check if an object is an orphan related to a certain relation() its supposed to belong to, though there's no automated way to go from that object to the actual collection it was removed from unless you scan through all

[sqlalchemy] Sorting by related property

2009-03-19 Thread Joril
Hi everyone! I have a simple many-to-one relation between class A and class B, and I'd like to use a Query to get the A instances sorted by a B attribute (e.g. code).. I tried with something like this: q = session.query(A) q.order_by(A.list_of_b.code) but obviously list_of_b doesn't know about

[sqlalchemy] Re: Sorting by related property

2009-03-19 Thread Joril
On 19 Mar, 15:09, Martin mar...@chinasoftinc.com wrote: I guess q = session.query(A).join('b').order_by(B.code).all() should do the trick, at least it did under 0.4.8 It works in 0.5.2 too, thanks :) I was wondering though, maybe 0.5.x has a way to do it without the join? I mean, SQLA

[sqlalchemy] Re: Database migrations using declarative

2009-03-06 Thread Joril
On 5 Mar, 18:40, Michael Bayer mike...@zzzcomputing.com wrote: im finding it easiest to just autoload the tables in my migrate script.   That way there's no cut and paste the table def going on, you just load them as they are from the DB.  and the schema definition stays in the database for

[sqlalchemy] Database migrations using declarative

2009-03-05 Thread Joril
Hi everyone! I'm looking for a way to handle database migrations/upgrades and found projects such as sqlalchemy-migrate and mikuru.. My understanding is that those projects expect the model to be in NON-declarative form, that is, with users_table = Table(...) and the like.. But what if my program

[sqlalchemy] Infinite recursion trying to deserialize any restriction

2009-02-17 Thread Joril
Hi everyone! I have a simple one-to-many relation between two classes, and I'm trying to serialize/deserialize an any restriction on them.. My problem is that deserialization fails with maximum recursion depth exceeded. Am I doing something wrong? Here's my testcase: from sqlalchemy import

[sqlalchemy] Re: Abstract base class

2008-12-18 Thread Joril
Michael Bayer wrote: meta = MetaData() Base1 = declarative_base(metadata=meta, metaclass=MyMetaClass) Base2 = declarative_base(metadata=meta, metaclass=MyOtherMetaClass) Base2._decl_class_registry = Base1._decl_class_registry Great! So now I have a MetaClass2 that extends MetaClass1, and

[sqlalchemy] Re: Abstract base class

2008-12-18 Thread Joril
Michael Bayer wrote(): isinstance(obj, (Base1, Base2)), or you could make yet another Base class below Base1 and Base2 and specify it as cls to declarative_base(). I see.. Thanks again, you are very helpful! --~--~-~--~~~---~--~~ You received this message

[sqlalchemy] Re: Mapping an array of strings?

2008-12-16 Thread Joril
Michael Bayer ha scritto: hibernate-style custom types are documented here: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/types.html?highlight=typeengine#custom-types or you can use PickleType. Perfect, many thanks! --~--~-~--~~~---~--~~ You

[sqlalchemy] Mapping an array of strings?

2008-12-15 Thread Joril
Hi everyone! Is there a way to (declaratively) map a class so that one of its members is an array of strings? (As an example use-case, a User class with an array of her websites) With Hibernate I'd just register a custom persister that would serialize the array/list to a big varchar field, is

[sqlalchemy] Pickling a restriction

2008-12-10 Thread Joril
Hi everyone! Is there a way to pickle a Query restriction? If I try this: import cPickle restr = (MyDataClass.intproperty==1) cPickle.dumps(restr, 1) I get a cPickle.PicklingError: Can't pickle class 'sqlalchemy.orm.properties.ColumnComparator': attribute lookup

[sqlalchemy] Re: Pickling a restriction

2008-12-10 Thread Joril
Michael Bayer ha scritto: There's a new extension in 0.5 which allows pickling of any ORM structure called sqlalchemy.ext.serializer. I see, thanks :) Although the error below shouldn't occur in any case, try out the latest trunk. Do you mean normal Pickle shouldn't raise the

[sqlalchemy] Re: Data logging and many-to-many's

2008-11-20 Thread Joril
Quite complicated, I see X-) Anyway, I've been able to implement the clean way you suggested (or at least the test suite says so :) ).. Many thanks again for your time, you've been very helpful! (Thanks to Svil too for your contribution!) --~--~-~--~~~---~--~~ You

[sqlalchemy] Re: Data logging and many-to-many's

2008-11-19 Thread Joril
On 19 Nov, 16:28, Michael Bayer [EMAIL PROTECTED] wrote: a guaranteed stable way that doesn't rely on SQLAlchemy implementation details and is easy to understand is here.  this is how I would do it: http://pastebin.com/f6670eebe I see, many thanks for yor time :) Out of curiosity, is there a

[sqlalchemy] Re: Data logging and many-to-many's

2008-11-19 Thread Joril
On 19 Nov, 17:22, Michael Bayer [EMAIL PROTECTED] wrote: Out of curiosity, is there a solution that wouldn't require creating new instances of the objects? (Some magic incantation like the del instance_state(entity).key you suggested me some time ago, I guess..?) not really since you'd

[sqlalchemy] Re: Filtering a primaryjoin

2008-11-06 Thread Joril
On 5 Nov, 18:17, Joril [EMAIL PROTECTED] wrote: I'd like to add a filter to a relation, so that it ignores records of the remote table if they're flagged as logically_deleted (a boolean field of the child table) Solved, children = relation(Child, primaryjoin=and_(id == Child.parent_id

[sqlalchemy] How to know if a lazy relation isn't loaded yet?

2008-11-03 Thread Joril
Hi everyone! I tried googling but found nothing.. Is there a way to know beforehand whether a relation would be lazy-loaded? For example, given a lazy parent-children relation and an instance X of parent, I'd like to know if X.children is already loaded, without triggering the query. Thanks in

[sqlalchemy] Re: Documentation on declarative relations

2008-10-31 Thread Joril
Lawrence Oluyede ha scritto: Have a look here: http://www.sqlalchemy.org/docs/05/plugins.html#plugins_declarative Didn't think of looking at the plugins section at all X-) Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the

[sqlalchemy] Documentation on declarative relations

2008-10-30 Thread Joril
Hi everyone! I'm sorry, I can't find documentation on how to specify relations using the declarative syntax.. Could someone provide a pointer? Thanks for your time! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

[sqlalchemy] Query representation

2008-10-06 Thread Joril
Hi everyone! I'm looking for a way to log queries at a higher level than SQL.. That is, given the class Base = declarative_base() class DataTest(Base): id = Column(Integer, primary_key = True) propb = Column(Boolean) __tablename__ = t right now when I try to print a query

[sqlalchemy] Data logging

2008-10-06 Thread Joril
Hi everyone! I'm trying to implement data logging with SQLAlchemy.. That is, whenever someone updates a persisted entity, generate a new record and then mark the old one as such. My problem right now is that if I load an entity from the DBMS, modify it and then try to save it again, I have to

[sqlalchemy] Re: Data logging

2008-10-06 Thread Joril
Perfect! Thanks again! --~--~-~--~~~---~--~~ 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 this group, send email to [EMAIL

[sqlalchemy] Re: Query representation

2008-10-06 Thread Joril
On 6 Ott, 16:26, Michael Bayer [EMAIL PROTECTED] wrote: Alternatively you could visit and compile the clause directly with your own compiler, which subclasses compiler.DefaultCompiler and overrides visit_bindparam() to return a string representation of the data instead of a param name. I

[sqlalchemy] Losing object state after rollback

2008-10-02 Thread Joril
Hi everyone! I'm sorry, I'm using SQLA 0.5rc1 with autocommit=True, and I'm having a problem with rollbacks.. It looks to me that whenever I try to save an object that triggers some kind of exception (thus triggering a rollback) I lose that object's previous state.. To elaborate, here's a simple

[sqlalchemy] Declarative and common fields

2008-09-29 Thread Joril
Hi everyone! I'm new to SQLAlchemy and I'm using version 0.5rc1.. I need every entity class to have a few common fields, so I tried writing an abstract base class, declarative-style, that every other entity class would subclass. So for example: --- from sqlalchemy.ext.declarative import

[sqlalchemy] Re: Declarative and common fields

2008-09-29 Thread Joril
I don't know whether this is currently possible with Declarative or not. In the case it isn't, patching Declarative should be quite easy (but I don't know if such a patch would be accepted or not). I see.. I'll wait a bit then, maybe one of the developers will tell us if it'd be acceptable :)

[sqlalchemy] Optimistic locking

2007-05-20 Thread Joril
Hi everyone! I'm sorry, I tried the documentation but couldn't find this piece of information.. How do I implement optimistic locking with SA? I mean, is there a framework for versioning fields? (The way Hibernate does) Should I do it by hand? Many thanks for your attention!

[sqlalchemy] Re: Optimistic locking

2007-05-20 Thread Joril
Oops, found version_id_col at http://www.sqlalchemy.org/docs/adv_datamapping.html, sorry! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to