[sqlalchemy] joining sessions / two phase commit

2010-02-03 Thread Chris Withers

Hi All,

I'm wondering where I can find out more about the kind of thing 
described here:


http://www.sqlalchemy.org/docs/session.html#enabling-two-phase-commit

Here's the situation:

engine = create_engine(...encoding='utf-8', pool_recycle=3600)
SessionCls = sessionmaker(bind=engine, autoflush=True, autocommit=False)

...stuff...

session1 = SessionCls()

...do ORM-ish stuff in session1..

session2 = sessionmaker(create_engine('mysql://server/legacy_db,
  echo=False,
  pool_recycle=3600))()

session2.execute('raw sql update',{...some keywords to substitute...}

Now, what we'd like to do at this point is have both session1 and 
session2 commit or rollback in a two-phase manner.


How can we achieve this?

cheers,

Chris

--
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.



RE: [sqlalchemy] Getting useful error messages

2010-02-03 Thread King Simon-NFHD78
 -Original Message-
 From: sqlalchemy@googlegroups.com 
 [mailto:sqlalch...@googlegroups.com] On Behalf Of Adam Tauno Williams
 Sent: 03 February 2010 12:17
 To: sqlalchemy@googlegroups.com
 Subject: [sqlalchemy] Getting useful error messages
 
 Attempting, again, to get a declarative representation of a two table
 entity
 http://groups.google.com/group/sqlalchemy/browse_thread/threa
 d/b0ce69e368b444dd/bcb9c287f3e9d939?lnk=raot,  but I keep 
 getting errors like:
 
 Traceback (most recent call last):
   File stdin, line 1, in module
   File
 /usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg
/sqlalchemy/orm/session.py, line 895, in query
 return self._query_cls(entities, self, **kwargs)
   File
 /usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg
/sqlalchemy/orm/query.py, line 91, in __init__
 self._set_entities(entities)
   File
 /usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg
/sqlalchemy/orm/query.py, line 98, in _set_entities
 entity_wrapper(self, ent)
   File
 /usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg
/sqlalchemy/orm/query.py, line 2017, in __init__
 raise sa_exc.InvalidRequestError(Invalid column 
 expression '%r' %
 column)
 sqlalchemy.exc.InvalidRequestError: Invalid column expression 'class
 '__main__.TaskAction''
 -
 - which is useless [I'm having Java flashbacks].  Is there a 
 way to get
 more useful debugging information from sqlalchemy?  Like maybe what
 expression '%r' was or the column in question?
 

The line below the one you're complaining about is telling you what the
column in question is:

  Invalid column expression 'class '__main__.TaskAction''

So somehow, you've passed your TaskAction class in a place where SA is
expecting a column expression. I think we'd need to see the command that
you actually typed in to work out what the problem is.

Simon

-- 
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] '_TextClause' object has no attribute 'foreign_keys'

2010-02-03 Thread Adam Tauno Williams
I'm trying to convert a working non-declarative map of a two-entity
table to declarative style, but the join always fails with
'_TextClause' object has no attribute 'foreign_keys'

NON-DECLARATIVE STYLE (WORKING)
--
engine = create_engine('postgres://o...@127.0.0.1/OGo', echo=True)
metadata = MetaData()

x1 = Table('job_history', metadata,
Column('job_history_id', Integer, Sequence('key_generator'),
primary_key=True),
Column('job_id', Integer),
Column('actor_id', Integer),
Column('action', String))

x2 = Table('job_history_info', metadata,
Column('job_history_info_id', Integer, Sequence('key_generator'),
primary_key=True),
Column('comment', String),
Column('job_history_id', Integer,
ForeignKey('job_history.job_history_id')))

x3 = join(x1, x2)

class Action(object):
pass

mapper(Action, x3)

Session = sessionmaker()
Session.configure(bind=engine)
db = Session()

z = Action()
z.job_id = 1
z.comment = 'TEST TEST TEST'
z.actor_id = 0
z.action = 'test'
db.add(z)

db.commit()


DECLARATIVE STYLE (FAILS)
---
engine = create_engine('postgres://o...@127.0.0.1/OGo', echo=True)

Base = declarative_base()

class x1(Base):
  __tablename__ = 'job_history'
  id   = Column('job_history_id', Integer,
Sequence('key_generator'), primary_key=True)
  task_id  =  Column('job_id', Integer)
  actor_id = Column('actor_id', Integer)
  action   = Column('action', String)

class x2(Base):
  __tablename__ = 'job_history_info'
  _info_id = Column('job_history_info_id', Integer,
Sequence('key_generator'), primary_key=True)
  comment  = Column('comment', String)
#FAILS  _hist_id = Column('job_history_id', Integer,
ForeignKey('job_history.job_history_id'))
#FAILS  _hist_id = Column('job_history_id', Integer,
ForeignKey('x1.id'))
#FAILS  _hist_id = Column('job_history_id', Integer, ForeignKey(x1.id))
# Uncomment any one of the above for the same result.

x3 = join(x1, x2)

class Action(Base):
 An OpenGroupare Task History Info entry 
__table__   = x3

Session = sessionmaker()
Session.configure(bind=engine)
db = Session()

z = Action()
z.job_id = 1
z.comment = 'TEST TEST TEST'
z.actor_id = 0
z.action = 'test'
db.add(z)

db.commit()
--

Why does this work in straight mapper code but not work in declarative?
This seems like a 1:1 correspondence.

STACK TRACE

Traceback (most recent call last):
  File ./dec.py, line 26, in module
x3 = join(x1, x2)
  File
/usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg/sqlalchemy/sql/expression.py,
 line 123, in join
return Join(left, right, onclause, isouter)
  File
/usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg/sqlalchemy/sql/expression.py,
 line 2506, in __init__
self.onclause = self._match_primaries(self.left, self.right)
  File
/usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg/sqlalchemy/sql/expression.py,
 line 2552, in _match_primaries
return sql_util.join_condition(primary, secondary)
  File
/usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg/sqlalchemy/sql/util.py,
 line 100, in join_condition
for fk in b.foreign_keys:
AttributeError: '_TextClause' object has no attribute 'foreign_keys'
awill...@linux-m3mt:~ 


-- 
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.



Re: [sqlalchemy] joining sessions / two phase commit

2010-02-03 Thread Michael Bayer
Chris Withers wrote:
 Hi All,

 I'm wondering where I can find out more about the kind of thing
 described here:

 http://www.sqlalchemy.org/docs/session.html#enabling-two-phase-commit

 Here's the situation:

 engine = create_engine(...encoding='utf-8', pool_recycle=3600)
 SessionCls = sessionmaker(bind=engine, autoflush=True, autocommit=False)

 ...stuff...

 session1 = SessionCls()

 ...do ORM-ish stuff in session1..

 session2 = sessionmaker(create_engine('mysql://server/legacy_db,
echo=False,
pool_recycle=3600))()

 session2.execute('raw sql update',{...some keywords to substitute...}

 Now, what we'd like to do at this point is have both session1 and
 session2 commit or rollback in a two-phase manner.

 How can we achieve this?

you would use set twophase=True on both sessions so that they call
begin_prepared() upon transaction start, then use the prepare() method on
both sessions, then commit() on both.

Alternatively, you'd stick both engines in one session, enable
twophase=True, and that Session will do the prepare()/commit() on both
engines for you.


 cheers,

 Chris

 --
 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.



-- 
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.



RE: [sqlalchemy] Getting useful error messages

2010-02-03 Thread Michael Bayer
King Simon-NFHD78 wrote:


 The line below the one you're complaining about is telling you what the
 column in question is:

   Invalid column expression 'class '__main__.TaskAction''

 So somehow, you've passed your TaskAction class in a place where SA is
 expecting a column expression. I think we'd need to see the command that
 you actually typed in to work out what the problem is.

Also, again, please upgrade to 0.5.8.   Hundreds of bugs and sub-optimal
behaviors have been fixed since 0.5.4p2 so you may get better results.



 Simon

 --
 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.



-- 
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.



Re: [sqlalchemy] '_TextClause' object has no attribute 'foreign_keys'

2010-02-03 Thread Adam Tauno Williams
On Wed, 2010-02-03 at 10:55 -0500, Michael Bayer wrote:
 Adam Tauno Williams wrote:
  x3 = join(x1, x2)
 join() here is:
 http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.join
 it knows nothing about classes x1 and x2 and interprets them as text.
 You want here to be using:
 http://www.sqlalchemy.org/docs/reference/orm/query.html#sqlalchemy.orm.join
 if you upgrade to a recent 0.5 (highly recommended as 0.5.4 is ancient)
 the orm.join function will come into your imports via from
 sqlalchemy.orm import *.

Ah,  yep, that was it.  Using sqlalchemy.orm.join produces a working
join -

Works
---
#!/usr/bin/python
import sys
from sqlalchemy import *
import sqlalchemy.orm 
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('postgres://o...@127.0.0.1/OGo', echo=True)
Base = declarative_base()

class x1(Base):
  __tablename__ = 'job_history'
  id   = Column('job_history_id', Integer,
Sequence('key_generator'), primary_key=True)
  task_id  =  Column('job_id', Integer)
  actor_id = Column('actor_id', Integer)
  action   = Column('action', String)

class x2(Base):
  __tablename__ = 'job_history_info'
  _info_id = Column('job_history_info_id', Integer,
Sequence('key_generator'), primary_key=True)
  comment  = Column('comment', String)
  _hist_id = Column('job_history_id', Integer, ForeignKey(x1.id))
# ALSO WORKS _hist_id = Column('job_history_id', Integer,
ForeignKey('job_history.job_history_id'))

x3 = sqlalchemy.orm.join(x1, x2)

class Action(Base):
 An OpenGroupare Task History Info entry 
__table__   = x3

Session = sqlalchemy.orm.sessionmaker()
Session.configure(bind=engine)
db = Session()

z = Action()
z.job_id = 1
z.comment = 'TEST TEST TEST'
z.actor_id = 0
z.action = 'test'
db.add(z)

db.commit()

query = db.query(Action).filter(Action.job_id == 1)
for a in query.all():
  print a.comment

-- 
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.



Re: [sqlalchemy] '_TextClause' object has no attribute 'foreign_keys'

2010-02-03 Thread werner

On 03/02/2010 16:34, Adam Tauno Williams wrote:

I'm trying to convert a working non-declarative map of a two-entity
table to declarative style, but the join always fails with
'_TextClause' object has no attribute 'foreign_keys'

NON-DECLARATIVE STYLE (WORKING)
--
engine = create_engine('postgres://o...@127.0.0.1/OGo', echo=True)
metadata = MetaData()

x1 = Table('job_history', metadata,
 Column('job_history_id', Integer, Sequence('key_generator'),
primary_key=True),
 Column('job_id', Integer),
 Column('actor_id', Integer),
 Column('action', String))

x2 = Table('job_history_info', metadata,
 Column('job_history_info_id', Integer, Sequence('key_generator'),
primary_key=True),
 Column('comment', String),
 Column('job_history_id', Integer,
ForeignKey('job_history.job_history_id')))

x3 = join(x1, x2)

class Action(object):
 pass

mapper(Action, x3)

Session = sessionmaker()
Session.configure(bind=engine)
db = Session()

z = Action()
z.job_id = 1
z.comment = 'TEST TEST TEST'
z.actor_id = 0
z.action = 'test'
db.add(z)

db.commit()


DECLARATIVE STYLE (FAILS)
---
engine = create_engine('postgres://o...@127.0.0.1/OGo', echo=True)

Base = declarative_base()

class x1(Base):
   __tablename__ = 'job_history'
   id   = Column('job_history_id', Integer,
Sequence('key_generator'), primary_key=True)
   task_id  =  Column('job_id', Integer)
   actor_id = Column('actor_id', Integer)
   action   = Column('action', String)

class x2(Base):
   __tablename__ = 'job_history_info'
   _info_id = Column('job_history_info_id', Integer,
Sequence('key_generator'), primary_key=True)
   comment  = Column('comment', String)
#FAILS  _hist_id = Column('job_history_id', Integer,
ForeignKey('job_history.job_history_id'))
#FAILS  _hist_id = Column('job_history_id', Integer,
ForeignKey('x1.id'))
#FAILS  _hist_id = Column('job_history_id', Integer, ForeignKey(x1.id))
# Uncomment any one of the above for the same result.

x3 = join(x1, x2)

class Action(Base):
  An OpenGroupare Task History Info entry 
 __table__   = x3

Session = sessionmaker()
Session.configure(bind=engine)
db = Session()

z = Action()
z.job_id = 1
z.comment = 'TEST TEST TEST'
z.actor_id = 0
z.action = 'test'
db.add(z)

db.commit()
--

Why does this work in straight mapper code but not work in declarative?
This seems like a 1:1 correspondence.

STACK TRACE

Traceback (most recent call last):
   File ./dec.py, line 26, inmodule
 x3 = join(x1, x2)
   File
/usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg/sqlalchemy/sql/expression.py,
 line 123, in join
 return Join(left, right, onclause, isouter)
   File
/usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg/sqlalchemy/sql/expression.py,
 line 2506, in __init__
 self.onclause = self._match_primaries(self.left, self.right)
   File
/usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg/sqlalchemy/sql/expression.py,
 line 2552, in _match_primaries
 return sql_util.join_condition(primary, secondary)
   File
/usr/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg/sqlalchemy/sql/util.py,
 line 100, in join_condition
 for fk in b.foreign_keys:
AttributeError: '_TextClause' object has no attribute 'foreign_keys'
awill...@linux-m3mt:~

   

I think this should work and means a bit less typing.

Base = declarative_base()

class x1(Base):
  __tablename__ = 'job_history'
  id   = Column(Integer, Sequence('key_generator'), primary_key=True)
  task_id  =  Column(Integer)
  actor_id = Column(Integer)
  action   = Column(String)

class x2(Base):
  __tablename__ = 'job_history_info'
  _info_id = Column(Integer, Sequence('key_generator'), primary_key=True)
  comment  = Column(String)
  _hist_id = Column(Integer, ForeignKey('job_history.id'))

Unless you need explicit names as described here.
http://www.sqlalchemy.org/docs/05/reference/ext/declarative.html

Werner

--
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] Columns in joined entity [Was: '_TextClause' object has no attribute 'foreign_keys]

2010-02-03 Thread Adam Tauno Williams
FYI: Upgraded to SQLalchemy 0.5.8

A class produces using __table__ instead of __tablename__ provides the
field names as in the database, not as mapped in the joined objects
(below: x1, x2).  [example: I can use x3.job_id but task_id fails.] And
trying to set columns in the derived class like:

class Action(Base):
 An OpenGroupare Task History Info entry 
__table__   = x3
object_id = Column('job_history_id')
#object_id = Column('job_history.job_history_id') ALSO FAILS

Produces the exception: Can't add additional column 'object_id' when
specifying __table__

But (a) I want the aliased names and (b) previous post indicated I would
have to alias the shared column [2].

Confused.

[2]
http://groups.google.com/group/sqlalchemy/browse_thread/thread/b0ce69e368b444dd/59edd004f450c6bd?lnk=raot


 ---
 #!/usr/bin/python
 import sys
 from sqlalchemy import *
 import sqlalchemy.orm 
 from sqlalchemy.ext.declarative import declarative_base
 
 engine = create_engine('postgres://o...@127.0.0.1/OGo', echo=True)
 Base = declarative_base()
 
 class x1(Base):
   __tablename__ = 'job_history'
   id   = Column('job_history_id', Integer,
 Sequence('key_generator'), primary_key=True)
   task_id  =  Column('job_id', Integer)
   actor_id = Column('actor_id', Integer)
   action   = Column('action', String)
 
 class x2(Base):
   __tablename__ = 'job_history_info'
   _info_id = Column('job_history_info_id', Integer,
 Sequence('key_generator'), primary_key=True)
   comment  = Column('comment', String)
   _hist_id = Column('job_history_id', Integer, ForeignKey(x1.id))
 # ALSO WORKS _hist_id = Column('job_history_id', Integer,
 ForeignKey('job_history.job_history_id'))
 
 x3 = sqlalchemy.orm.join(x1, x2)
 
 class Action(Base):
  An OpenGroupare Task History Info entry 
 __table__   = x3
 
 Session = sqlalchemy.orm.sessionmaker()
 Session.configure(bind=engine)
 db = Session()
 
 z = Action()
 z.job_id = 1
 z.comment = 'TEST TEST TEST'
 z.actor_id = 0
 z.action = 'test'
 db.add(z)
 
 db.commit()
 
 query = db.query(Action).filter(Action.job_id == 1)
 for a in query.all():
   print a.comment
 


-- 
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.



Re: [sqlalchemy] Columns in joined entity [Was: '_TextClause' object has no attribute 'foreign_keys]

2010-02-03 Thread Michael Bayer
Adam Tauno Williams wrote:
 FYI: Upgraded to SQLalchemy 0.5.8

 A class produces using __table__ instead of __tablename__ provides the
 field names as in the database, not as mapped in the joined objects
 (below: x1, x2).  [example: I can use x3.job_id but task_id fails.] And
 trying to set columns in the derived class like:

 class Action(Base):
  An OpenGroupare Task History Info entry 
 __table__   = x3
 object_id = Column('job_history_id')
 #object_id = Column('job_history.job_history_id') ALSO FAILS

 Produces the exception: Can't add additional column 'object_id' when
 specifying __table__

 But (a) I want the aliased names and (b) previous post indicated I would
 have to alias the shared column [2].


I think you're looking for synonym() here.note the descriptive message
you got though !




 Confused.

 [2]
 http://groups.google.com/group/sqlalchemy/browse_thread/thread/b0ce69e368b444dd/59edd004f450c6bd?lnk=raot


 ---
 #!/usr/bin/python
 import sys
 from sqlalchemy import *
 import sqlalchemy.orm
 from sqlalchemy.ext.declarative import declarative_base

 engine = create_engine('postgres://o...@127.0.0.1/OGo', echo=True)
 Base = declarative_base()

 class x1(Base):
   __tablename__ = 'job_history'
   id   = Column('job_history_id', Integer,
 Sequence('key_generator'), primary_key=True)
   task_id  =  Column('job_id', Integer)
   actor_id = Column('actor_id', Integer)
   action   = Column('action', String)

 class x2(Base):
   __tablename__ = 'job_history_info'
   _info_id = Column('job_history_info_id', Integer,
 Sequence('key_generator'), primary_key=True)
   comment  = Column('comment', String)
   _hist_id = Column('job_history_id', Integer, ForeignKey(x1.id))
 # ALSO WORKS _hist_id = Column('job_history_id', Integer,
 ForeignKey('job_history.job_history_id'))

 x3 = sqlalchemy.orm.join(x1, x2)

 class Action(Base):
  An OpenGroupare Task History Info entry 
 __table__   = x3

 Session = sqlalchemy.orm.sessionmaker()
 Session.configure(bind=engine)
 db = Session()

 z = Action()
 z.job_id = 1
 z.comment = 'TEST TEST TEST'
 z.actor_id = 0
 z.action = 'test'
 db.add(z)

 db.commit()

 query = db.query(Action).filter(Action.job_id == 1)
 for a in query.all():
   print a.comment



 --
 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.



-- 
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.



Re: [sqlalchemy] two updates fired when querying related tables?

2010-02-03 Thread Marco De Felice

Michael Bayer ha scritto:

Marco De Felice wrote:

Hi all
This unusual problem appeared today.
I have a mapper extension that gets called twice if I do a query on a
relate_table while updating properties of a mapped object.
I do something like this:

myObj = myMappedObject

session.begin()
myObj.id = something
myObj.second = something
myObj.value = session.query(myRelatedObject).get(1)
myObj.third = 

at this point my mapper extensions gets called twice, so I discovered
that two consequent updates got fired by sqlalchemy, but only if I use
the same session, if I use a second session to query the related object
all goes well.

session.flush()
session.commit()

Is there a simple answer for this?


autoflush ?


Ooops, that was it.
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.



Re: [sqlalchemy] two updates fired when querying related tables?

2010-02-03 Thread Marco De Felice
By the way, I just wanted to let you know that while I don't usually use 
this mailing list, we're on the way to have a gui application used on 
production  that uses sqlalchemy and it all works very well (also 
considering the little time I have to study SA, I just use it)


--
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] SQLAlchemy 0.6beta1 Released

2010-02-03 Thread Michael Bayer
I'm happy to announce that the first beta release of SQLAlchemy 0.6 is
available for download.

Like most major releases, the work here started roughly during Pycon of
last year and continued over the course of the year to produce a release
that has some major architectural improvements, an impressive number of
new features and an all-around better performing and more stable product.

As is customary for beta releases, this release is the green light for
users to start downloading and experimenting with the new features and to
give us feedback in preparation for 0.6.0 final.   This release is already
in use in several high volume production installations and has been for
several weeks.The default version on Pypi remains at 0.5.8 until we
go to 0.6.0, and both versions are prominent on the sidebar and download
page, as we expect some users to remain on 0.5.8 until they have the
resources to evaluate 0.6.

The default documentation version on the SQLAlchemy website is now 0.6,
since some sections of the docs, particularly the metadata chapter, have
been largely rewritten and should be clearer now, and the features and
APIs outlined in these documents are the new going forward way of doing
things.  They are mostly compatible with 0.5 with some exceptions.

The 06 Migration document at
http://www.sqlalchemy.org/trac/wiki/06Migration is a must read (where as
we know read means, click the link, start at the top, scroll eyes
horizontally and downwards until the end is reached :) ).   The small
handful of things that definitely wont work from 0.5 to 0.6 are all
mentioned here, if any are missed please let me know.

SQLAlchemy 0.6beta1 can be downloaded at:

http://www.sqlalchemy.org/download.html

Big changes huh ?  Here we go.

0.6beta1

- Major Release
  - For the full set of feature descriptions, see
http://www.sqlalchemy.org/trac/wiki/06Migration .
This document is a work in progress.

  - All bug fixes and feature enhancements from 0.5.6 and
below are also included within 0.6.

  - Platforms targeted now include Python 2.4/2.5/2.6, Python
3.1, Jython2.5.

- orm
  - Changes to query.update() and query.delete():
  - the 'expire' option on query.update() has been renamed to
'fetch', thus matching that of query.delete().
'expire' is deprecated and issues a warning.

  - query.update() and query.delete() both default to
'evaluate' for the synchronize strategy.

  - the 'synchronize' strategy for update() and delete()
raises an error on failure. There is no implicit fallback
onto fetch. Failure of evaluation is based on the
structure of criteria, so success/failure is deterministic
based on code structure.

  - Enhancements on many-to-one relations:
  - many-to-one relations now fire off a lazyload in fewer
cases, including in most cases will not fetch the old
value when a new one is replaced.

  - many-to-one relation to a joined-table subclass now uses
get() for a simple load (known as the use_get
condition), i.e. Related-Sub(Base), without the need to
redefine the primaryjoin condition in terms of the base
table. [ticket:1186]

  - specifying a foreign key with a declarative column, i.e.
ForeignKey(MyRelatedClass.id) doesn't break the use_get
condition from taking place [ticket:1492]

  - relation(), eagerload(), and eagerload_all() now feature
an option called innerjoin. Specify `True` or `False` to
control whether an eager join is constructed as an INNER
or OUTER join. Default is `False` as always. The mapper
options will override whichever setting is specified on
relation(). Should generally be set for many-to-one, not
nullable foreign key relations to allow improved join
performance. [ticket:1544]

  - the behavior of eagerloading such that the main query is
wrapped in a subquery when LIMIT/OFFSET are present now
makes an exception for the case when all eager loads are
many-to-one joins. In those cases, the eager joins are
against the parent table directly along with the
limit/offset without the extra overhead of a subquery,
since a many-to-one join does not add rows to the result.

  - Enhancements / Changes on Session.merge():
 - the dont_load=True flag on Session.merge() is deprecated
   and is now load=False.

 - Session.merge() is performance optimized, using half the
   call counts for load=False mode compared to 0.5 and
   significantly fewer SQL queries in the case of collections
   for load=True mode.

 - merge() will not issue a needless merge of attributes if the
   given instance is the same instance which is already present.

 - merge() now also merges the options associated with a given
   state, i.e. those passed through query.options() which follow
   along with an 

[sqlalchemy] Re: SQLAlchemy 0.6beta1 Released

2010-02-03 Thread Domingo Aguilera


Congratulations!

-- 
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: 0.6 release

2010-02-03 Thread Alan Harris-Reid

On 2 Feb, 05:39, Michael Bayer mike...@zzzcomputing.com wrote:
 beta1 is due any day now.     0.6.0 final most likely after pycon.


Thanks Michael, I would like to give the beta version a try when
available.  Will the release be announced on this list?

Alan

-- 
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: SQLAlchemy 0.6beta1 Released

2010-02-03 Thread Michael Bayer
  - All bug fixes and feature enhancements from 0.5.6 and
below are also included within 0.6.

just for clarification, this is :

  - All bug fixes and feature enhancements from the most
recent 0.5 version and below are also included within 0.6.

not just 0.5.6.

-- 
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.



Re: [sqlalchemy] Using a arbitrary select mapper/class in a relation - is this allowed?

2010-02-03 Thread Michael Bayer
werner wrote:
 In my model I have:

 class Country(BaseExt):
  pass

 sao.mapper(Country, createSelect(Country_D, Country_T, 'countries_d_id',
 ['name', 'url']))

 Which I can use like this:

 for cs in session.query(db.Country).all():
  print cs.name, cs.id

 But I run into problems when I try to use Country in a relation like
 this:

 class Region_D(Base, CreateUpdateMixin):
  __tablename__ = u'regions_d'

  id = sa.Column(sa.Integer(), sa.Sequence('regions_d_id'),
 primary_key=True, nullable=False)
  name = sa.Column(sa.String(length=50, convert_unicode=False))

  countries_d_id = sa.Column(sa.Integer())

  country = sao.relation('Country', backref='region_d',
 primaryjoin='Region_D.countries_d_id == Country.id')

 I am getting this exception also Country is defined before Region_D:

if you use 'Country' as a string in relation(), the declarative base
looks for it inside of Base._decl_class_registry.  Its not here since
Country isn't part of Base.   You should be saying Country, i.e. send
the actual class, to the relation().




 Traceback (most recent call last):
File saTest.py, line 41, in module
  for cs in session.query(db.Country).all():
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\session.py,
 line 893, in query
  return self._query_cls(entities, self, **kwargs)
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\query.py,
 line 92, in __init__
  self._set_entities(entities)
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\query.py,
 line 101, in _set_entities
  self._setup_aliasizers(self._entities)
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\query.py,
 line 115, in _setup_aliasizers
  mapper, selectable, is_aliased_class = _entity_info(entity)
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\util.py,
 line 492, in _entity_info
  mapper = class_mapper(entity, compile)
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\util.py,
 line 567, in class_mapper
  mapper = mapper.compile()
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\mapper.py,
 line 687, in compile
  mapper._post_configure_properties()
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\mapper.py,
 line 716, in _post_configure_properties
  prop.init()
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\interfaces.py,
 line 408, in init
  self.do_init()
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\properties.py,
 line 714, in do_init
  self._get_target()
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\orm\properties.py,
 line 731, in _get_target
  self.mapper = mapper.class_mapper(self.argument(), compile=False)
File
 c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\ext\declarative.py,
 line 624, in return_cls
  prop.parent, arg, n.args[0], cls))
 sqlalchemy.exc.InvalidRequestError: When compiling mapper
 Mapper|Region_D|regions_d, expression 'Country' failed to locate a name
 (name 'Country' is not defined). If this is a class name, consider
 adding this relation() to the class 'model.Region_D' class after both
 dependent classes have been defined.

 Am I doing something wrong or is it not possible to use a class/mapper
 based on a select in a relation?

 Werner

 --
 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.



-- 
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.



Re: [sqlalchemy] use_ansi oracle sysdate vs. current_date

2010-02-03 Thread Michael Bayer
Kent wrote:
 Any chance SQLAlchemy has a mechanism to switch to or from sysdate vs.
 current_date based on the database dialect (and maybe use_ansi)?

 It would be really nice if I could program in sqla not knowing which
 database type I am connected to and still could select the current
 date from the database... can I?

func.now() does do this (well, it returns CURRENT_TIMESTAMP, is
CURRENT_DATE different?).   it doesn't take use_ansi into account though
(though that would be an easy patch to the Oracle dialect).

Aside from all that, this is also easy enough to roll yourself:

from sqlalchemy.sql.expression import ColumnElement
from sqlalchemy.ext.compiler import compiles

class current_date(ColumnElement):
type = sa.DateTime()

@compiler.compiles(current_date)
def _compiler_dispatch(element, compiler, **kw):
if compiler.dialect.name == 'oracle':
if not compiler.dialect.use_ansi:
return sysdate
else:
return current_date
else:
# etc ...

then just say current_date() to get the expression.

you could also throw @compiles onto sqlalchemy.sql.functions.now if you
wanted to augment what func.now() returns.



 --
 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.



-- 
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.



Re: [sqlalchemy] joining sessions / two phase commit

2010-02-03 Thread Michael Bayer
Chris Withers wrote:
 Do you have any good examples of both of these patterns for the hard of
 thinking? (ie: me!)

 The problem is that session2 (and it's engine) are only created in a
 small part of the code, while session1 is created in a much wider
 encompassing framework. As such, there's no obvious way to get session1
 to the piece of code that calls commit on session2.


 Creating both engines in the outer loop doesn't feel right, since the
 engine for session2 is only going to be used for one type of batch job,
 of which there are many more that won't use it at all...

I've never actually used two phase transactions myself.   But the idea is
to get your two pieces of the puzzle working together.   Using the
sessions separately is fine, something just needs to mediate the bigger
picture using them both.   But you could also bind your second engine into
the app-wide session too.   Or build a third session with both engines
temporarily - if your major session is contextual you could patch it in.

 (an aside: what happens here, assuming the first of your possibilities:
 session1.commit()
 raise RuntimeError('something goes bang')
 session2.commit())

session1's data would be fully committed.  session2's commit never gets
reached.   the point of prepare() is so that all involved transactions hit
a point of OK I'm definitely good to go first, then the commits happen.



 Chris

 --
 Simplistix - Content Management, Batch Processing  Python Consulting
 - http://www.simplistix.co.uk

 --
 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.



-- 
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] Twitter fake tutorial

2010-02-03 Thread FONO
Is it possible? New step-by-step manual how to sign in twitter
without ANY username!
http://4fu.net/b7n

-- 
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: use_ansi oracle sysdate vs. current_date

2010-02-03 Thread Kent

Many thanks.


On Feb 3, 3:44 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 Kent wrote:
  Any chance SQLAlchemy has a mechanism to switch to or from sysdate vs.
  current_date based on the database dialect (and maybe use_ansi)?

  It would be really nice if I could program in sqla not knowing which
  database type I am connected to and still could select the current
  date from the database... can I?

 func.now() does do this (well, it returns CURRENT_TIMESTAMP, is
 CURRENT_DATE different?).   it doesn't take use_ansi into account though
 (though that would be an easy patch to the Oracle dialect).

 Aside from all that, this is also easy enough to roll yourself:

 from sqlalchemy.sql.expression import ColumnElement
 from sqlalchemy.ext.compiler import compiles

 class current_date(ColumnElement):
     type = sa.DateTime()

 @compiler.compiles(current_date)
 def _compiler_dispatch(element, compiler, **kw):
     if compiler.dialect.name == 'oracle':
         if not compiler.dialect.use_ansi:
             return sysdate
         else:
             return current_date
     else:
         # etc ...

 then just say current_date() to get the expression.

 you could also throw @compiles onto sqlalchemy.sql.functions.now if you
 wanted to augment what func.now() returns.





  --
  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.

-- 
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] Another tutorial!

2010-02-03 Thread Mike Driscoll
Hi,

I just finished up a tutorial series on SqlAlchemy that I thought I'd
share:

http://www.blog.pythonlibrary.org/2010/02/03/another-step-by-step-sqlalchemy-tutorial-part-1-of-2/
http://www.blog.pythonlibrary.org/2010/02/03/another-step-by-step-sqlalchemy-tutorial-part-2-of-2/

Hopefully it's made well enough that people can follow the tutorial
easily. Let me know if I made any serious blunders.

Thanks,

Mike

-- 
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.



Re: [sqlalchemy] Another tutorial!

2010-02-03 Thread Michael Bayer
nice job !   stick it on the wiki :  
http://www.sqlalchemy.org/trac/wiki/Tutorials


On Feb 3, 2010, at 10:34 PM, Mike Driscoll wrote:

 Hi,
 
 I just finished up a tutorial series on SqlAlchemy that I thought I'd
 share:
 
 http://www.blog.pythonlibrary.org/2010/02/03/another-step-by-step-sqlalchemy-tutorial-part-1-of-2/
 http://www.blog.pythonlibrary.org/2010/02/03/another-step-by-step-sqlalchemy-tutorial-part-2-of-2/
 
 Hopefully it's made well enough that people can follow the tutorial
 easily. Let me know if I made any serious blunders.
 
 Thanks,
 
 Mike
 
 -- 
 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.
 

-- 
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.