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 emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


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

2014-04-03 Thread Joril
Hi everyone!
I have a client-server application where sometimes I need to modify a 
cascaded member of a one-to-many relation directly, that is by saving 
itself instead of its parent. This works, but if later the user *does* save 
the parent, I get a A conflicting state is already present in the identity 
map error, and I don't know if I'm simply doing something I'm not supposed 
to :)

I narrowed down the issue to this example:


from sqlalchemy import Column, String, Integer, Table, ForeignKey
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Child(Base):
   __tablename__ = children

   id = Column(Integer, primary_key=True)
   parent_id = Column(Integer, ForeignKey(parents.id))

class Parent(Base):
   __tablename__ = parents

   id = Column(Integer, primary_key=True)
   children = relationship(Child, cascade=save-update, uselist=True)

en = create_engine(sqlite:///:memory:, echo=True)
Base.metadata.create_all(en) 
maker = sessionmaker(en)
session = maker(autocommit=True) 

# Save a parent with a child
par = Parent()
par.children = [ Child() ]
session.add(par)
session.flush()

child_id = par.children[0].id # For later

# Clean the session (simulate another client-server session)
session.expunge_all()

# Reload the children
q = session.query(Child)
q = q.filter(Child.id == child_id)
child_reloaded = q.first()

# Reassign to the parent 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._save_or_update_state(state)
  File /home/joril/src/newprg/branches/sqla09/sqlalchemy/orm/session.py, 
line 1497, in _save_or_update_state
self._save_or_update_impl(st_)
  File /home/joril/src/newprg/branches/sqla09/sqlalchemy/orm/session.py, 
line 1746, in _save_or_update_impl
self._update_impl(state)
  File /home/joril/src/newprg/branches/sqla09/sqlalchemy/orm/session.py, 
line 1739, in _update_impl
self.identity_map.add(state)
  File /home/joril/src/newprg/branches/sqla09/sqlalchemy/orm/identity.py, 
line 119, in add
% (key, ))
AssertionError: A conflicting state is already present in the identity map 
for key (class '__main__.Child', (1,))

Is this supposed to happen?

Many thanks!

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


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 Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[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 = q.filter(entities.A.list_of_Cs.any(entities.C.value  entities.B.value)

but the generated SQL looks like:

SELECT [...fields...]
FROM a JOIN b ON a.id = b.a_id
WHERE EXISTS (SELECT 1 
FROM C, B
WHERE A.id = C.a_id AND C.value  B.value)

As you can see, the inner select doesn't get B.value from the main query as 
in my original one, instead it introduces a new join between C and B...
I tried replacing entities.B like this:
b_alias = entities.B.__table__.alias()
but I still get a join inside the subquery... What am I missing?

Many thanks!
(SQLAlchemy 0.7.9)

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[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() # Issues a BEGIN that marks transaction boundary
session.add(obj1)
session.flush()
tx.prepare()

then from another session

session = sessionmaker(engine)(autocommit=True)
session.connection().commit_prepared(xid, recover=True) # recover=True
because otherwise it complains that you can't issue a COMMIT PREPARED
from inside a transaction

This doesn't raise any error, but doesn't write anything to the table
either... O_o What am I missing?

I tried even blocking the application after the prepare() and issuing
a COMMIT PREPARED 'xid' from pgadmin, but still nothing gets written.

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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 way like that, you need to set session.bind = connection, then the 
 Session will do everything in terms of that connection.  You could skip the 
 autocommit/begin/flush and just do a single session.commit(), which from the 
 tx point of view would not be the actual commit.

 Session has a public API for this, though it doesn't at the moment accept the 
 XID, but you can grab the one it generates:

 session = sessionmaker(engine)
 session.prepare()
 session.add(obj1)
 session.flush()

The prepare() should be called _before_ issuing changes to the DB? I
thought it was a substitute for the first commit()... Anyway, so after
the flush the transaction will be in a prepared state and waiting
for the COMMIT PREPARED? I'll try it, thanks :)

 either way should work, but turning on SQL echo is the best way to see what 
 is/is not happening.

Yes I have echo active but it looks like I misunderstood the sequence
of commands to give :/

Many thanks for your time!

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



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 
could use the xid to refer to the same transaction from every request, but 
it looks like BEGIN PREPARED doesn't exist, and if I issue a second 
PREPARE TRANSACTION 'samexid' it complains that the transaction 
identifier xyz is already in use

Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/7UroIxI3UfkJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



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 :)

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/B9HdeSaJeb0J.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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

A Post has an Owner, while TagAssociation has a Tag, a Post and an
Onwer

Between TagAssociation and Post there's a many-to-one, and I'd like to
configure a tags backref so that it would handle only the
TagAssociations having the same Owner as the Post... Is this possible?

Many thanks!

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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 specified in Query get attached to lazy loaders later in the chain, 
 if the given joinedload() chain doesn't start from the entity being queried 
 (which is probably the case if the query uses joinedload() and not 
 joinedload_all()).

Problem solved, many thanks :)

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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, having a LEFT OUTER JOIN on the VAT table too... Other
times the lazy-loading query joins only Detail and Product.
I think I'm doing something fishy here.. What could I check, to ensure
that the lazy loading doesn't touch unneeded entities?

Many thanks!

(SQLAlchemy 0.6.6, PGSQL 8.3)

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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 nicely, but I'm having a little problem..
I'm on the client, with a detached lazy-loaded object having a
cascaded one-to-many relation, and I just want to clear this relation,
such as:

obj.children = []

but it complains that obj is not bound to a Session and that the
lazy load operation of attribute 'children' cannot proceed. This used
to work with SA 0.5.8, but now we're using 0.6.5... What am I missing?

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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 
 this kind of thing in a consistent way, usually the strategy is to narrow 
 down the series of DBAPI calls to a pure MySQL-python script that continues 
 to reproduce.   Its tricky though.

I see... I did a few more tests, and it looks like the problem arises
consistently when executing multiple statements having a syntax error
in the second (or later) one..

Extending your example:

from sqlalchemy import *
e = create_engine('mysql://scott:tiger@localhost/test', echo=True)
e.execute(select * from validtable; this is crap)

This returns a ResultProxy, but on the NEXT execution (even if a
correct one) SQLAlchemy logs a

INFO sqlalchemy.engine.base.Engine.0x...4acL ()
Exception _mysql_exceptions.ProgrammingError: (1064, You have an
error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'this is crap'
at line 1) in bound method Cursor.__del__ of MySQLdb.cursors.Cursor
object at 0xb743238c ignored

Maybe I could persuade SA-migrate to execute one statement at a
time...
Thanks for your assistance :)

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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 closing cursor: (1064, You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near 'NOT NULL' at line 1)

and doesn't propagate the exception, so the outer code won't know that
something went wrong.. In my case, this means that migrate commits che
transaction and I end up with a partially-applied change script.

Am I doing something wrong?

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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 
 collections during flush, in that your append got flushed but the delete 
 doesn't - there's specific code to that effect, which is also not consistent 
 against one-to-many.  I've added ticket 1973 which, if it proceeds, would 
 likely be in 0.7.


Great, thanks :)

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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
4) deassociate the child and save the parent

the association doesn't get removed from the junction table.. If I
skip closing the session, it DOES get removed...
Here's an example:


from sqlalchemy import Column, String, Integer, Table, ForeignKey
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

junction = Table(junction, Base.metadata, Column(p_id,
ForeignKey(parents.id)),
Column(c_id,
ForeignKey(children.id)))

class Child(Base):
   __tablename__ = children

   id = Column(Integer, primary_key=True)

class Parent(Base):
   __tablename__ = parents

   id = Column(Integer, primary_key=True)
   children = relationship(Child, secondary=junction, cascade=)


def save(session, x):
   session.add(x)
   session.flush()

en = create_engine(sqlite:///:memory:, echo=True)
Base.metadata.create_all(en)
maker = sessionmaker(en)
session = maker(autocommit=True)

# Save a child and close the session
c = Child()
save(session, c)
session.close()

# Associate the child to a parent and save
p = Parent()
p.children = [c]
save(session, p)

# Try to remove the child
p.children = []
save(session, p)


I'd expect that the last command would log something like

BEGIN (implicit)
SELECT children.id AS children_id
FROM children
WHERE children.id = ?
(1,)
DELETE FROM junction WHERE junction.p_id = ? AND junction.c_id = ?
(1, 1)
COMMIT
SELECT parents.id AS parents_id
FROM parents
WHERE parents.id = ?
(1,)


but instead I get only


BEGIN (implicit)
COMMIT
SELECT parents.id AS parents_id
FROM parents
WHERE parents.id = ?
(1,)


This used to work with 0.5.8, what am I doing wrong?

Many thanks for your attention!

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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 your 
 __mapper_args__ on Base:

 class Base(object):
     version = Column(Integer)

     @declared_attr
     def __mapper_args__(cls):
         return {'version_id_col':cls.version}

 Base = declarative_base(cls=Base)

Very nice! Thanks :)

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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 like this:


class MyMeta(DeclarativeMeta):

def __init__(cls, classname, bases, dict_):
cls.version = Column(Integer)
cls.__mapper_args__ = { version_id_col : cls.version }
return DeclarativeMeta.__init__(cls, classname, bases, dict_)

Base = declarative_base(metaclass=MyMeta)

class Entity(Base):

 __tablename__ = entities
 whatever...


but I think I'm missing something, since even a simple

print Entity().__mapper__.version_id_col

produces a (no name) instead of something like entities.version,
so I'm guessing that some part of SA doesn't see the
version_id_col...?

I understand that SA 0.6 includes a Declarative Mixin feature, but
that would require to touch-up every class declaration to include the
mixin, am I right? It'd be no big deal, but I'd prefer to keep that
complexity away, if it's possible... :)

So my question is: since it was possible with SA 0.5, is there a way
to specify a version_id_col in a custom DeclarativeMeta using 0.6?

Many thanks for your attention!

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[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, aut_trasporto), (base_files, aut_stoccaggio),
(aut_stoccaggio, jun_cer_abilitati_aut_stoccaggi), (aut_stoccaggio,
conf), (aut_stoccaggio, formulari), (targhe,
jun_cer_abilitati_targhe), (targhe, formulari), (formulari_dett,
fatture_dett), (formulari_dett, ddt_dett), (aut_trasporto, formulari),
(aut_trasporto, conf), (aut_trasporto, targhe), (ddt_dett,
fatture_dett), (formulari, formulari_dett), (formulari, base_files)][]

But I can't understand how the circle comes into play, since the new
triggering relation has as many side an entity with just plain
attributes (Unicode/Integer/DateTime).. So my question: what is the
list of table names that follows CircularDependencyError? Should I use
it to find out where the circular dependency is?

Thanks for your time!
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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, getattr(src, prop.key))

  but I'm having troubles with lazy relations... Obviously getattr
  triggers the lazy loading, but since I don't need their values right
  away, I'd like to just copy the this should be lazy loaded-state of
  the attribute... Is this possible?

 I did something similar. I iterated on class_mapper().columns to get the
 attributes to populate. That approach skipped all the relations, and in my
 case was exactly what I wanted


I see, but I need a proper shallow copy instead, with every
attribute.. Is there no way? :/

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 object when instantiated.
 Obviously the objects pointed to by the relation are not copied, but I would
 call that a deep copy, and to do that you would need to iterate over them
 also.

I'm sorry, by shallow copy I mean that only the parent object should
be a copy (=different instance), while the related ones should be kept
as-is...

For example, given an object A that references B and C, a shallow copy
of A would be made up of a copy of A that references the original B
and C (not copies of B or C).

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 triggers the query, and I'd like to avoid that,
while still copying the fact that Acopy.refs should be the same as
A.refs.

Thanks for your attention 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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 triggers the query, and I'd like to avoid that,
  while still copying the fact that Acopy.refs should be the same as
  A.refs.

 So, let's understand the underlying data model.

 We say, A is a parent object related to B and C children.
 (1) If this is a one-to-many relationship, then B and C will contain foreign
 keys pointing at A. Copying of A to Acopy cannot have references point at
 [B, C] because the children cannot point at two parents at the same time;
 there is only one foreign key column.
 (2) If this is a many-to-many relationship, then there will be another table
 between A and [B,C] managing the many-to-many connection and something needs
 to be done during the copy to preserve the relationships.

 Which do we have here?


Ehr.. Both :) I'm looking for a generic way to build a shallow copy,
so the relations could be of any type.
Anyway, now that you point it out I'm thinking that maybe there's no
way to just copy the informations that would allow SQLA to perform the
lazy loading from the new instance, since this instance would have no
ID at all, and SQLA couldn't possibly match it with related data..
Maybe that could have worked with Hibernate, since it uses Proxy
objects to implement lazy loading..

Many thanks for your assistance! :)
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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?
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 has a version attribute too, so I can't use a simple
DBMS-level autoincrementing field

I'm trying to build this using a custom Type that would kick in every
time an invoice gets saved. Whenever process_bind_param is called with
a None value, it will call a singleton of some sort to determine the
number and avoid collisions. Is this a decent solution?

Anyway, I'm having a problem.. Here's my custom Type:

class AutoIncrement(types.TypeDecorator):
impl = types.Unicode

def copy(self):
return AutoIncrement()

def process_bind_param(self, value, dialect):
if not value:
# Must find next autoincrement value
value = 1 # Test value :)
return value


My problem right now is that when I save an Invoice and AutoIncrement
sets 1 as value for its number, the Invoice instance *doesn't* get
updated with the new number.. Is this expected? Am I missing
something?
Many thanks for your time!

(SQLA 0.5.3 on Python 2.6, using postgreSQL 8.3)
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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, thanks for your time!
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 eventually the related Cs) where C.value has the
maximum value, given the same D.

So for example, given a table D made of
[id, otherfield]
(1, A)
(2, B)
(3, C)

and a table C made of
[id, d_id, value]
(1, 1, 0)
(2, 1, 1) - max value for d_id 1
(3, 2, 3) - max value for d_id 2
(4, 2, 2)

I'd like my query to return
[d.id, c.id]
(1, 2)
(2, 3)
(3, None)

Is this possible with a single query?
Many thanks for your time!
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 (
 select d_id, max(value) as v from c group by d_id) as sub
  on c.d_id = sub.d_id and c.value = sub.v) as c
   on c.d_id = d.id

Now I'll try with the Query API :) But I was wondering, maybe there's
a simpler way than 3 nested queries...?

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 postgreSQL complained that
 column c.id must appear in the GROUP BY clause or be used in an aggregate 
 function
I think this is because given N rows with the same d_id, the DBMS
can't figure out which C.id to return, even if I'd like it to choose
the one corresponding to the current maxvalue :/
Or maybe I'm missing something?
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 = s.query(C.d_id, func.max(C.value).label(v)).group_by
(C.d_id).subquery()
sub2 = s.query(C).join((sub, and_(C.d_id==sub.c.d_id,
C.value==sub.c.v))).subquery()
q = s.query(D, sub2.c.id).outerjoin(sub2)

so the result is instances of D along the (eventually) related C.id..
Now let's see if I can fetch complete instances of C instead of just
the id X-)
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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,
  and_(C.d_id==sub.c.d_id, C.value==sub.c.v))).subquery()
idmap = s.query(D.id.label(did), sub2.c.id.label(cid)).
  outerjoin(sub2).subquery()
q = s.query(D, C).join((idmap, idmap.c.did==D.id)).
  outerjoin((C, idmap.c.cid==C.id))

Yields complete instances of D and C, having maximum C.value where
relevant :)
I must say that SQLAlchemy keeps amazing me.. Many thanks to everyone!
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 the potential parents in the session and check each one.

 the current way to check for an orphan is and internal thing at the
 moment, and looks like:

 some_relation.mapper._is_orphan(attributes.instance_state(item))

I see, thanks :)
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 codes.. How should I do
it?

Many thanks!
(SQLA 0.5.2)
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 should have all the informations to figure it out
by itself, I think..?
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 those who get bent out of shape about that.  problem solved.
  the migrate docs should suggest this too.

I see, thanks for your help :) (And Kevin's too of course)
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 uses exclusively declarative? Can I use them all the same? Or
are there tools that work with declarative, or should I roll my own?

Many thanks for your time!
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 Column, Integer, String, ForeignKey
from sqlalchemy.ext import serializer
from sqlalchemy.orm import relation
from sqlalchemy.ext.declarative import declarative_base

# Tables definition
Base = declarative_base()

class Child(Base):
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey(parent.id))
data = Column(String)

class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
children = relation(Child)

# Build any restriction
r = Parent.children.any(Child.data==x)

# Serialize and deserialize it
ser = serializer.dumps(r)
serializer.loads(ser, Base.metadata)


Thanks for your time!
(tried with SQLA 0.5.0 and 0.5.2, Python 2.5.2)

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 they share a
set of fields.. Works perfectly :)

Another question if I may.. What would be the recommended way to
identify a mapped object now? I mean, I could use something like
isinstance(obj, Base1) or isinstance(obj, Base2)
but is there a more concise way? It looks like Base1 and Base2 extend
object directly..

 This is a use case we can make easier in a future release.

That'd be appreciated, surely :)

Many thanks for your time, as always!
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 there a way to do
this with SQLA?

Many thanks!
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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.orm.properties.ColumnComparator failed

Many thanks for your time!
--~--~-~--~~~---~--~~
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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 PicklingError in my
case? I tried with a simpler test:

from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy import Column, Integer

import cPickle



Base = declarative_base()



class Test(Base):

__tablename__ = 'test'

id = Column(Integer, primary_key=True)



restr = Test.id==1

cPickle.dumps(restr,1)


but it throws the same error (I'm using 0.5rc4, but I tried rev 5457
too)

--~--~-~--~~~---~--~~
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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 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..?)
--~--~-~--~~~---~--~~
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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 have to manually recreate the history attributes
 for the children list in order for SQLA to see those items as newly
 added, thus resulting in the rules that establish the association to be
 invoked.

I see.. But - sorry if I insist - are you implying that it would be
too difficult to do? I know it'd be a kind of ugly hack, but since I
spent almost the whole day looking for it, now I'm wondering if I was
looking for something that doesn't exist at all X-)

 since the path of create and associate objects like normal
 python objects is the path of usage the ORM was designed for, that's the
 one that will work without danger of being impacted by implementation
 details.

Yes of course.. 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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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,
Child.logically_deleted==False))

Thanks anyway!
--~--~-~--~~~---~--~~
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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 advance!
--~--~-~--~~~---~--~~
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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 restriction:

restr=(DataTest.propb==False)
print restr

I get something like

t.propb = :propb_1

Is there a way to get

propb = False
?

I know I can fetch the operands via restr.left.name and
restr.right.value, but what about the operator?
Many thanks for your help!
--~--~-~--~~~---~--~~
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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 tell SQLA that the entity
needs to be INSERTed, not UPDATEd.. I tried zeroing entity.id and
entity.version, but it still tries an UPDATE.. How do I trick SQLA
into thinking it's a new entity?

Many thanks for your time!
--~--~-~--~~~---~--~~
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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 found a solution using compiler.operator_string(), but yours looks
much nicer.. I'll try it, 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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 testcase:



from sqlalchemy import Column, String, Integer
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class DataTest(Base):
 Simple class with versioning 
id = Column(Integer, primary_key = True)
propstring = Column(String)
version = Column(Integer)
__tablename__ = t
__mapper_args__ = { version_id_col : version }

def save(session, x):
 Save x with begin/commit 
session.begin()
session.add(x)
session.commit()

en=create_engine(sqlite:///:memory:, echo=True)
Base.metadata.create_all(en)
maker = sessionmaker(en)
session = maker(autocommit=True)

# Save a DataTest...
x=DataTest()
x.propstring = test
save(session, x)

# ...then simulate a concurrent modification
x.version=0
try:
save(session, x)
except:
session.rollback()

# I'd expect x.version to be the way it was
assert x.version == 0



Am I misunderstanding something? Is there a way to keep x the way it
was before the save() ?
Many thanks for your attention!
--~--~-~--~~~---~--~~
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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 declarative_base
from sqlalchemy import Column, String, DateTime, Integer

ORMBase = declarative_base()

class BaseObject(ORMBase):
id = Column(Integer, primary_key=True)
creation_time = Column(DateTime)
modify_time = Column(DateTime)

class TestEntity(BaseObject):
value = Column(String)
---

But SQLAlchemy complains that
sqlalchemy.exc.ArgumentError: Mapper 'Mapper|BaseObject|None' does not
have a mapped_table specified.  (Are you using the return value of
table.create()?  It no longer has a return value.)

Is there a way to tell SQLAlchemy to treat BaseObject like a non-
mapped-class? I tried using ORMBase as mixin to TestEntity (so
BaseObject extends object and TestEntity extends BaseObject and
ORMBase), but now I get a

sqlalchemy.exc.ArgumentError: Mapper Mapper|TestEntity|tests could not
assemble any primary key columns for mapped table 'tests'

so I guess that maybe I'm going down the wrong road.. Am I doing
something that Declarative doesn't like? :) Should I try Elixir
instead?

Many thanks for your time!
--~--~-~--~~~---~--~~
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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 :)

 If you don't want to go down that route, Elixir does support that pattern.

Do you mean these
http://elixir.ematia.de/trac/wiki/FAQ#HowdoIaddfunctionalitytoallmyentitiestothebaseclass
http://elixir.ematia.de/trac/wiki/FAQ#HowdoIprovideadifferentbaseclassthanEntity
?

The comment Note that in this case you'll lose all default methods
provided by the Entity class makes me think that extending Entity
isn't supported even in Elixir, have I got it wrong?
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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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!


--~--~-~--~~~---~--~~
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 PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[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 sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---