Re: [sqlalchemy] Updating user interface after rollback (using after_rollback SessionExtension?)

2011-08-02 Thread Torsten Landschoff
Hi Michael,

On Mon, 2011-08-01 at 14:18 -0400, Michael Bayer wrote:

 The Session's default behavior is to expire fully the state present after a 
 rollback occurs.   The next access of any attribute will guaranteed pull 
 fresh from the DB in a new transaction. 
 
 I'm assuming you know this, and that there is something additional here 
 you're looking for, like an event to the GUI to actually re-access the 
 attributes, or something.

Exactly.

 A surprise for me.Yes the after_rollback() seems to only fire
 after an actual database rollback.  This is a bug in that there is no
 way to catch soft rollbacks.  I can't change the event, as it is
 integral in transactional extensions like that supplied for Zope; a
 new one will have to be added and the docs for after_rollback() will
 need to be updated.

Actually I expected after_rollback to fire only after an actual DB
rollback. Or did I misinterpret the errors in that the rollback came
before a flush to the database and therefore no actual reload from the
database would be needed?

 Ticket #2241 is added for this and is completed.   You can now use the
 0.7 tip and use the after_soft_rollback() event in conjunction with
 the is_active flag:
 
 @event.listens_for(Session, after_soft_rollback)
 def do_something(session, previous_transaction):
 if session.is_active:
 session.execute(select * from some_table)

I looked at the is_active flag in SQLAlchemy 0.6.8 already and I think I
can only use it with autocommit disabled. Unfortunately I use
autocommit=True.

I know that's a bad choice from the SQLAlchemy point of view. The reason
why I am using it is that I want to avoid to keep the database locked
over a long time, as this makes our background processes fail
(OperationalError: Database is locked). I am a victim of the limitations
of SQLite here :-(

Perhaps after the current stabilization phase, I will move to SA 0.7 and
autocommit=False. I am not sure about the latter though.

Thanks and Greetings, Torsten

-- 
DYNAmore Gesellschaft fuer Ingenieurdienstleistungen mbH
Torsten Landschoff

Office Dresden
Tel: +49-(0)351-4519587
Fax: +49-(0)351-4519561

mailto:torsten.landsch...@dynamore.de
http://www.dynamore.de

Registration court: Mannheim, HRB: 109659, based in Karlsruhe,
Managing director:  Prof. Dr. K. Schweizerhof, Dipl.-Math. U. Franz

-- 
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] Relationship spanning on multiple tables

2011-08-02 Thread neurino
Sorry Michael,

there was a typo in my code, due to some wrong copy/paste or search/replace
I guess, I'm afraid.

The error I reported comes up mapping to `TransmLimit` and not `SurfaceRes`
(which is the one already mapped above).

I edited the pastebin:

http://pastebin.com/mjfgPrcB

now with:

'transm_limit': relationship(TransmLimit, single_parent=True,
uselist=False,
primaryjoin=and_(
user_stratigraphies.c.id_prov==provinces.c.id,
provinces.c.id_cz==transm_limits.c.id_cz,
user_stratigraphies.c.id_str==stratigraphies.c.id,
stratigraphies.c.id_tec==tech_elements_classes.c.id,
tech_elements_classes.c.id_tu==transm_limits.c.id_tu,
),
foreign_keys=(
user_stratigraphies.c.id_prov,
),
),

I get the error I reported:

sqlalchemy.exc.ArgumentError: Could not locate any foreign-key-equated,
locally mapped column pairs for primaryjoin condition
'user_stratigraphies.id_prov = provinces.id AND provinces.id_cz =
transm_limits.id_cz AND user_stratigraphies.id_str = stratigraphies.id AND
stratigraphies.id_tec = tech_elements_classes.id AND
tech_elements_classes.id_tu = transm_limits.id_tu' on relationship
ustratatigraphy.transm_limit.  For more relaxed rules on join conditions,
the relationship may be marked as viewonly=True.

Also there's the strange `viewonly=True` behavior that breakes
`UserStratigraphy.surface_res` relationship if uncommented.

Thanks for your patience.
neurino



On Mon, Aug 1, 2011 at 11:14 PM, Michael Bayer mike...@zzzcomputing.comwrote:

 'transm_limit': relationship(SurfaceRes, single_parent=True,
#uselist=False,
#primaryjoin=and_(
#user_stratigraphies.c.id_prov==provinces.c.id,
#provinces.c.id_cz==transm_limits.c.id_cz,
#user_stratigraphies.c.id_str==stratigraphies.c.id,
#stratigraphies.c.id_tec==tech_elements_classes.c.id,
#tech_elements_classes.c.id_tu==transm_limits.c.id_tu,
#),

 this fails because you aren't joining to the table to which SurfaceRes is
 mapped, surface_res.



 On Aug 1, 2011, at 7:02 AM, neurino wrote:

  I'm trying to get some relationships spanning on multiple tables (4 or
  5).
 
  While I got the `4 tables` one working on first attempt (I was
  surpized I could...) I can't get the `5 tables` one to work while the
  code is almost the same.
 
  Moreover with the first relationship if I add adding `viewonly=True`
  initialization fails.
 
  I just need these to get (not even set) some values with convenience
  of SA attributes.
 
  I published a working example on pastebin:
 
  http://pastebin.com/RsZ6GCRq
 
  I hope someone can sort out this thing, thank you.
 
  Greetings
  neurino
 
  --
  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.
 

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



-- 
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] Working with a ResultProxy object

2011-08-02 Thread RVince
In my controller class, I perform a rather basic, straightforward SQL
query:

connection = engine.connect()
trans = connection.begin()
try:
c.result = connection.execute(select
current_disposition_code,count(*) as num from cms_input_file group by
current_disposition_code;)
connection.close()

thus my c.result is an sqlalchemy.engine.base.ResultProxy object.

When I go to render this in a mako file as:

% for result in c.results:
${result.current_disposition_code}[${result.num}]
% endfor

I get no output. I am quite certain this is becuase I am using a
ResultProxy object. How can I output such an object inthe mako files,
or alternatively, how might i convert a ResultProxy objectsuch that I
can output it in a mako file? Thanks! RVince

-- 
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] Working with a ResultProxy object

2011-08-02 Thread Tamás Bajusz
On Tue, Aug 2, 2011 at 3:07 PM, RVince rvinc...@gmail.com wrote:
 In my controller class, I perform a rather basic, straightforward SQL
 query:

        connection = engine.connect()
        trans = connection.begin()
        try:
            c.result = connection.execute(select
 current_disposition_code,count(*) as num from cms_input_file group by
 current_disposition_code;)
            connection.close()

 thus my c.result is an sqlalchemy.engine.base.ResultProxy object.

 When I go to render this in a mako file as:

                % for result in c.results:
                ${result.current_disposition_code}[${result.num}]
        % endfor

 I get no output. I am quite certain this is becuase I am using a
 ResultProxy object. How can I output such an object inthe mako files,
 or alternatively, how might i convert a ResultProxy objectsuch that I
 can output it in a mako file? Thanks! RVince

Seems you missed fetching some rows from ResultProxy.
http://www.sqlalchemy.org/docs/core/connections.html#sqlalchemy.engine.base.ResultProxy

Hope this helps.

-- 
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: Working with a ResultProxy object

2011-08-02 Thread RVince
Tamas,

I'm more confused now -- would I do this in my controller or in the
mako file? If, in my controller, dont I need to create an array for
each field, that is:

i = 0
for row in c.result
c.current_disposition_code[i] = row['current_disposition_code']
c.num[i] = row['num']
i = i + 1

I dont see how I can move, say,  c.current_disposition_code and c.num
to the make output? I don't seem to be getting any output still (I'm
still missing something):

   % for result in c.current_disposition_code:
${result}
   % endfor

Thanks for your help and insight with this. RVince
On Aug 2, 9:26 am, Tamás Bajusz gbt...@gmail.com wrote:
 On Tue, Aug 2, 2011 at 3:07 PM, RVince rvinc...@gmail.com wrote:
  In my controller class, I perform a rather basic, straightforward SQL
  query:

         connection = engine.connect()
         trans = connection.begin()
         try:
             c.result = connection.execute(select
  current_disposition_code,count(*) as num from cms_input_file group by
  current_disposition_code;)
             connection.close()

  thus my c.result is an sqlalchemy.engine.base.ResultProxy object.

  When I go to render this in a mako file as:

                 % for result in c.results:
                 ${result.current_disposition_code}[${result.num}]
         % endfor

  I get no output. I am quite certain this is becuase I am using a
  ResultProxy object. How can I output such an object inthe mako files,
  or alternatively, how might i convert a ResultProxy objectsuch that I
  can output it in a mako file? Thanks! RVince

 Seems you missed fetching some rows from 
 ResultProxy.http://www.sqlalchemy.org/docs/core/connections.html#sqlalchemy.engin...

 Hope this helps.

-- 
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] Updating user interface after rollback (using after_rollback SessionExtension?)

2011-08-02 Thread Michael Bayer

On Aug 2, 2011, at 3:33 AM, Torsten Landschoff wrote:

 
 I looked at the is_active flag in SQLAlchemy 0.6.8 already and I think I
 can only use it with autocommit disabled. Unfortunately I use
 autocommit=True.

if you're in autocommit=True and you're calling session.flush() which fails, it 
rolls back just once, then the session is basically back to normal.  You 
shouldn't be getting that error you're getting (unless you're doing your own 
nesting with begin()/rollback(), in which case is_active counts).

Here's the full check for a Session that is usable:

session.transaction is None or session.is_active

with autocommit=True, session.transaction remains None when the Session is in 
between operations.


-- 
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] Working with a ResultProxy object

2011-08-02 Thread Michael Bayer

On Aug 2, 2011, at 9:07 AM, RVince wrote:

 In my controller class, I perform a rather basic, straightforward SQL
 query:
 
connection = engine.connect()

connection, OK

trans = connection.begin()

start a transaction, OK

try:
c.result = connection.execute(select
 current_disposition_code,count(*) as num from cms_input_file group by
 current_disposition_code;)


connection.close()

close the connection ?  what happened to trans, wheres the rollback or commit ? 
 what about your c.result that hasn't been iterated yet ?  both of these need 
an active Connection to proceed correctly. Technically the transaction is 
fine with just the connection.close() at the end but its a strange form that 
doesn't make the intent clear.The cursor referenced by the ResultProxy 
definitely should have exclusive access to its parent Connection for its whole 
lifespan, though, closing it out can have one of several negative effects, 
depending on the backend and the configuration of the connection pool.

Want to know what would be easy here ?

c.result = engine.execute(select * from my_table)

then you're done.   The ResultProxy in this case manages the Connection itself 
which will be closed when the ResultProxy closes. However this assumes you 
just need one SQL statement in a transaction, it seems that perhaps the begin() 
call is because you're doing several things with the one Connection.

Ideally, assuming this is Pylons, you'd have a single Connection declared for 
all controllers up in your BaseController, with a trans = connection.begin() at 
the top and trans.rollback() at the bottom.   That way the mechanics of 
providing database context to controllers is handled in application logic and 
not business logic.Or you'd have the ORM Session in place and just use 
Session.execute() to get a result.


-- 
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: Working with a ResultProxy object

2011-08-02 Thread RVince
Michael,

Right, thats a better idea -- I am working with snippets of other
people's code here. However, I still have the original problem of
going from a ResultProxy object to output in a mako file which is a
chasm I cannnot seem to bridge! RVInce

On Aug 2, 10:06 am, Michael Bayer mike...@zzzcomputing.com wrote:
 On Aug 2, 2011, at 9:07 AM, RVince wrote:

  In my controller class, I perform a rather basic, straightforward SQL
  query:

         connection = engine.connect()

 connection, OK

         trans = connection.begin()

 start a transaction, OK

         try:
             c.result = connection.execute(select
  current_disposition_code,count(*) as num from cms_input_file group by
  current_disposition_code;)
             connection.close()

 close the connection ?  what happened to trans, wheres the rollback or commit 
 ?  what about your c.result that hasn't been iterated yet ?  both of these 
 need an active Connection to proceed correctly.     Technically the 
 transaction is fine with just the connection.close() at the end but its a 
 strange form that doesn't make the intent clear.    The cursor referenced by 
 the ResultProxy definitely should have exclusive access to its parent 
 Connection for its whole lifespan, though, closing it out can have one of 
 several negative effects, depending on the backend and the configuration of 
 the connection pool.

 Want to know what would be easy here ?

 c.result = engine.execute(select * from my_table)

 then you're done.   The ResultProxy in this case manages the Connection 
 itself which will be closed when the ResultProxy closes.     However this 
 assumes you just need one SQL statement in a transaction, it seems that 
 perhaps the begin() call is because you're doing several things with the one 
 Connection.

 Ideally, assuming this is Pylons, you'd have a single Connection declared for 
 all controllers up in your BaseController, with a trans = connection.begin() 
 at the top and trans.rollback() at the bottom.   That way the mechanics of 
 providing database context to controllers is handled in application logic and 
 not business logic.    Or you'd have the ORM Session in place and just use 
 Session.execute() to get a result.

-- 
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] Re: Working with a ResultProxy object

2011-08-02 Thread Michael Bayer

On Aug 2, 2011, at 11:31 AM, RVince wrote:

 Michael,
 
 Right, thats a better idea -- I am working with snippets of other
 people's code here. However, I still have the original problem of
 going from a ResultProxy object to output in a mako file which is a
 chasm I cannnot seem to bridge! RVInce

there's nothing wrong with assigning a ResultProxy to c.result, then iterating 
it in a template, as long as the connection context remains open.   Your 
premature closing it is the likely issue here.



 
 On Aug 2, 10:06 am, Michael Bayer mike...@zzzcomputing.com wrote:
 On Aug 2, 2011, at 9:07 AM, RVince wrote:
 
 In my controller class, I perform a rather basic, straightforward SQL
 query:
 
connection = engine.connect()
 
 connection, OK
 
trans = connection.begin()
 
 start a transaction, OK
 
try:
c.result = connection.execute(select
 current_disposition_code,count(*) as num from cms_input_file group by
 current_disposition_code;)
connection.close()
 
 close the connection ?  what happened to trans, wheres the rollback or 
 commit ?  what about your c.result that hasn't been iterated yet ?  both of 
 these need an active Connection to proceed correctly. Technically the 
 transaction is fine with just the connection.close() at the end but its a 
 strange form that doesn't make the intent clear.The cursor referenced by 
 the ResultProxy definitely should have exclusive access to its parent 
 Connection for its whole lifespan, though, closing it out can have one of 
 several negative effects, depending on the backend and the configuration of 
 the connection pool.
 
 Want to know what would be easy here ?
 
 c.result = engine.execute(select * from my_table)
 
 then you're done.   The ResultProxy in this case manages the Connection 
 itself which will be closed when the ResultProxy closes. However this 
 assumes you just need one SQL statement in a transaction, it seems that 
 perhaps the begin() call is because you're doing several things with the one 
 Connection.
 
 Ideally, assuming this is Pylons, you'd have a single Connection declared 
 for all controllers up in your BaseController, with a trans = 
 connection.begin() at the top and trans.rollback() at the bottom.   That way 
 the mechanics of providing database context to controllers is handled in 
 application logic and not business logic.Or you'd have the ORM Session 
 in place and just use Session.execute() to get a result.
 
 -- 
 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.
 

-- 
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: Working with a ResultProxy object

2011-08-02 Thread RVince
Michael,

But if I do the following, and do NOT close it (at least, I dont
believe I am now):

result = engine.execute(select
current_disposition_code,count(*) as num from cms_input_file group by
current_disposition_code;)
c.curent_disposition_codes = []
c.num = []
for row in result:
 
c.curent_disposition_codes.append(str(row['current_disposition_code']))
c.num.append(str(row['num'] ))

And I look in at c.curent_disposition_codes and c.num, and I see 4
values for each, then, when I go to render it with:

%
i = 0
%
% for result in c.current_disposition_codes:
${result}[${c.num.index(i)}]
%
i = i + 1
%
% endfor

I get no output at all. The last bit of code, the mako file, is
executing, and properly, but it is not outputting values -- is there
something obvious that I am missing here? Thanks so much for your help
here. RVince

-- 
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] SQLAlchemy 0.7.2 Released

2011-08-02 Thread Martijn Moeling
Thank you for all the effort you put in.
SQLAlchemy has been a proven tool for me and as it seems for many others.



 
On Aug 1, 2011, at 02:17 , Michael Bayer wrote:

 SQLAlchemy version 0.7.2 is now available.
 
 A lot has been going on leading up to this release, and there was actually a 
 bunch more I've wanted to do;  but as we went about six weeks since the last 
 release we've accumulated at least twenty five bug fixes, and it's time for 
 them to go out.Work continues towards the next release.
 
 This release features a relatively big change to the mechanics of joined and 
 subquery eager loading, which is that when invoked from a Query (as opposed 
 to from a lazy load), the eager loader will traverse the graph of objects 
 fully regardless of collections and attributes that are already loaded, 
 populating any expired or not-yet-loaded attributes all the way down the 
 hierarchy.   Previously it tried to save time by not descending into already 
 loaded subtrees.   This is to better support the use case of using eager 
 loading in order to fully populate a tree, such that it can be detached and 
 sent to a cache in a fully loaded state.  It is also behaviorally closer to 
 the spirit of I asked for X, I should get X, i.e. if you say 
 subqueryload(), you'll get your subquery no matter what.
 
 Other than that there were a *lot* of ORM fixes, most of which have been also 
 applied to the 0.6 branch and will be in 0.6.9.  Also some additional 
 0.6-0.7 regressions fixed, and some fixes to the new Mutable extension 
 including one which was kind of a show stopper.
 
 Download SQLAlchemy 0.7.2 at:
 
 http://www.sqlalchemy.org/download.html
 
 Changelog follows.
 
 0.7.2
 =
 - orm
  - Feature enhancement: joined and subquery
loading will now traverse already-present related
objects and collections in search of unpopulated
attributes throughout the scope of the eager load
being defined, so that the eager loading that is
specified via mappings or query options
unconditionally takes place for the full depth,
populating whatever is not already populated.
Previously, this traversal would stop if a related
object or collection were already present leading
to inconsistent behavior (though would save on
loads/cycles for an already-loaded graph). For a
subqueryload, this means that the additional
SELECT statements emitted by subqueryload will
invoke unconditionally, no matter how much of the
existing graph is already present (hence the
controversy). The previous behavior of stopping
is still in effect when a query is the result of
an attribute-initiated lazyload, as otherwise an
N+1 style of collection iteration can become
needlessly expensive when the same related object
is encountered repeatedly. There's also an 
as-yet-not-public generative Query method 
_with_invoke_all_eagers()
which selects old/new behavior [ticket:2213]
 
  - A rework of replacement traversal within
the ORM as it alters selectables to be against
aliases of things (i.e. clause adaption) includes 
a fix for multiply-nested any()/has() constructs 
against a joined table structure.  [ticket:2195]
 
  - Fixed bug where query.join() + aliased=True
from a joined-inh structure to itself on 
relationship() with join condition on the child
table would convert the lead entity into the 
joined one inappropriately.  [ticket:2234]
Also in 0.6.9.
 
  - Fixed regression from 0.6 where Session.add()
against an object which contained None in a
collection would raise an internal exception.
Reverted this to 0.6's behavior which is to 
accept the None but obviously nothing is
persisted.  Ideally, collections with None 
present or on append() should at least emit a 
warning, which is being considered for 0.8.
[ticket:2205]
 
  - Load of a deferred() attribute on an object
where row can't be located raises 
ObjectDeletedError instead of failing later
on; improved the message in ObjectDeletedError
to include other conditions besides a simple
delete. [ticket:2191]
 
  - Fixed regression from 0.6 where a get history
operation on some relationship() based attributes
would fail when a lazyload would emit; this could 
trigger within a flush() under certain conditions.
[ticket:2224]  Thanks to the user who submitted
the great test for this.
 
  - Fixed bug apparent only in Python 3 whereby
sorting of persistent + pending objects during
flush would produce an illegal comparison,
if the persistent object primary key 
is not a single integer.  [ticket:2228]
Also in 0.6.9
 
  - Fixed bug whereby the source clause
used by query.join() would be inconsistent
if against a column expression that combined
multiple entities together.  [ticket:2197]
Also in 0.6.9
 
  - Fixed bug whereby if a mapped class
redefined __hash__() or 

Re: [sqlalchemy] Re: Working with a ResultProxy object

2011-08-02 Thread Michael Bayer

On Aug 2, 2011, at 12:09 PM, RVince wrote:

 Michael,
 
 But if I do the following, and do NOT close it (at least, I dont
 believe I am now):
 
result = engine.execute(select
 current_disposition_code,count(*) as num from cms_input_file group by
 current_disposition_code;)
c.curent_disposition_codes = []
c.num = []
for row in result:
 
 c.curent_disposition_codes.append(str(row['current_disposition_code']))
c.num.append(str(row['num'] ))
 
 And I look in at c.curent_disposition_codes and c.num, and I see 4
 values for each, then, when I go to render it with:
 
   %
   i = 0
   %
   % for result in c.current_disposition_codes:
   ${result}[${c.num.index(i)}]
   %
   i = i + 1
   %
   % endfor


In this case you are running through the result proxy in your controller, 
assigning to a collection, and its done.  That is perfectly fine.   Feel free 
to close out the connection after iterating the result set.

Then, it is unusual that you're indexing what is basically a string, i.e. each 
value of result with the [] operator though.



-- 
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] SQLAlchemy 0.7.2 Released

2011-08-02 Thread James Studdart
I'd just like to echo Martin's statement, thank you very much. Just your 
responses to this list seem like a full time job, let alone the 
development to SQLAlchemy - which continues to surprise and impress me 
with it's features and support.


James.

On 08/02/2011 09:28 AM, Martijn Moeling wrote:

Thank you for all the effort you put in.
SQLAlchemy has been a proven tool for me and as it seems for many others.




On Aug 1, 2011, at 02:17 , Michael Bayer wrote:

   

SQLAlchemy version 0.7.2 is now available.

A lot has been going on leading up to this release, and there was actually a 
bunch more I've wanted to do;  but as we went about six weeks since the last 
release we've accumulated at least twenty five bug fixes, and it's time for 
them to go out.Work continues towards the next release.

This release features a relatively big change to the mechanics of joined and subquery 
eager loading, which is that when invoked from a Query (as opposed to from a lazy load), 
the eager loader will traverse the graph of objects fully regardless of collections and 
attributes that are already loaded, populating any expired or not-yet-loaded attributes 
all the way down the hierarchy.   Previously it tried to save time by not descending into 
already loaded subtrees.   This is to better support the use case of using eager loading 
in order to fully populate a tree, such that it can be detached and sent to a cache in a 
fully loaded state.  It is also behaviorally closer to the spirit of I asked for X, 
I should get X, i.e. if you say subqueryload(), you'll get your subquery no matter 
what.

Other than that there were a *lot* of ORM fixes, most of which have been also applied to the 
0.6 branch and will be in 0.6.9.  Also some additional 0.6-0.7 regressions fixed, and 
some fixes to the new Mutable extension including one which was kind of a show 
stopper.

Download SQLAlchemy 0.7.2 at:

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

Changelog follows.

0.7.2
=
- orm
  - Feature enhancement: joined and subquery
loading will now traverse already-present related
objects and collections in search of unpopulated
attributes throughout the scope of the eager load
being defined, so that the eager loading that is
specified via mappings or query options
unconditionally takes place for the full depth,
populating whatever is not already populated.
Previously, this traversal would stop if a related
object or collection were already present leading
to inconsistent behavior (though would save on
loads/cycles for an already-loaded graph). For a
subqueryload, this means that the additional
SELECT statements emitted by subqueryload will
invoke unconditionally, no matter how much of the
existing graph is already present (hence the
controversy). The previous behavior of stopping
is still in effect when a query is the result of
an attribute-initiated lazyload, as otherwise an
N+1 style of collection iteration can become
needlessly expensive when the same related object
is encountered repeatedly. There's also an
as-yet-not-public generative Query method
_with_invoke_all_eagers()
which selects old/new behavior [ticket:2213]

  - A rework of replacement traversal within
the ORM as it alters selectables to be against
aliases of things (i.e. clause adaption) includes
a fix for multiply-nested any()/has() constructs
against a joined table structure.  [ticket:2195]

  - Fixed bug where query.join() + aliased=True
from a joined-inh structure to itself on
relationship() with join condition on the child
table would convert the lead entity into the
joined one inappropriately.  [ticket:2234]
Also in 0.6.9.

  - Fixed regression from 0.6 where Session.add()
against an object which contained None in a
collection would raise an internal exception.
Reverted this to 0.6's behavior which is to
accept the None but obviously nothing is
persisted.  Ideally, collections with None
present or on append() should at least emit a
warning, which is being considered for 0.8.
[ticket:2205]

  - Load of a deferred() attribute on an object
where row can't be located raises
ObjectDeletedError instead of failing later
on; improved the message in ObjectDeletedError
to include other conditions besides a simple
delete. [ticket:2191]

  - Fixed regression from 0.6 where a get history
operation on some relationship() based attributes
would fail when a lazyload would emit; this could
trigger within a flush() under certain conditions.
[ticket:2224]  Thanks to the user who submitted
the great test for this.

  - Fixed bug apparent only in Python 3 whereby
sorting of persistent + pending objects during
flush would produce an illegal comparison,
if the persistent object primary key
is not a single integer.  [ticket:2228]
Also in 0.6.9

  - Fixed bug 

[sqlalchemy] Re: Working with a ResultProxy object

2011-08-02 Thread RVince
LOL,I'm going backwards here, and taking far too long to get something
so very simple done (there's a genuine lack of documentation here I
think -- the only way to manage to learn much of this is by trial and
error).  Rather than trying to do this with straight SQL statements I
will go plan B here and try to rewrite their SQL library to be
consistent with the SQL alchemy idiom for selecting. This way, I will
get the output into these mako files.

-- 
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] Integrity error when using association_proxy - one of the foreign keys is missing

2011-08-02 Thread Benjamin Sims
Thanks so much for the help. For the record, setting an __init__ argument on 
the association argument did the trick. 

Ben 





On 2 Aug 2011, at 01:47, Michael Bayer mike...@zzzcomputing.com wrote:

 
 On Aug 1, 2011, at 8:34 PM, somewhatofftheway wrote:
 
 Hi,
 
 I'm trying to convert a 'simple' many-to-many relationship to an
 association object in order to allow the relationship to have
 attributes. I've followed the code in examples/association/
 proxied_association.py fairly closely (or so I thought) but it isn't
 working for me.
 
 As an example, let's say I am trying to create a relationship between
 an RSS feed and the pages from the feed but I want a feed_date on the
 relationship. Currently, my code look something like this:
 
 class Page (Base):
   __tablename__ = 'pages'
   id = Column(Integer, primary_key=True)
 
   posts = relationship(Post, cascade=all, delete-orphan,
   backref='pages')
   feeds = association_proxy(feeds, feed)
 
 
 class Post(Base)
   __tablename__ = 'pages_feeds'
   page_id = Column(Integer, ForeignKey('pages.id'),
 primary_key=True)
   feed_id = Column(Integer, ForeignKey('feeds.id'),
 primary_key=True)
   feed = relationship(Feed, lazy='joined')
 
 I haven't changed the Feed class at all.
 
 When I do something along the lines of:
 
 page = Page()
 feed = Feed()
 page.feeds.append(feed)
 
 the query that is issued is as follows:
 
 IntegrityError: (IntegrityError) pages_feeds.feed_id may not be NULL
 u'INSERT INTO pages_feeds (page_id) VALUES (?)' (1,)
 
 So, clearly I have missed out the part of the config that explains
 that adds in the second foreign key. Could anybody point me to where
 please?
 
 you need a constructor and/or creator that generates Post() with the feed 
 attached to it, like def __init__(self, feed): self.feed = feed, then the 
 assoc proxy with creator=Post.
 
 -- 
 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.
 

-- 
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] Re: Building hierarchy tree in reverse

2011-08-02 Thread Vlad K.


Yes I'm using PostgreSQL and now that you've linked to the docs, I 
remember there was a possibility for recursion. Thanks for suggestion, 
I'll look into it.


.oO V Oo.


On 08/02/2011 03:41 AM, Gunnlaugur Briem wrote:
You could look for recursive CTE (Common Table Expressions), if your 
database engine supports such queries. See e.g. 
http://www.postgresql.org/docs/8.4/static/queries-with.html for 
PostgreSQL. That allows arbitrary-depth queries, as opposed to join 
chains that have to assume a fixed depth. You could probably apply two 
recursive queries, one downward and one upward from the given node, to 
avoid querying the whole tree.


SQLAlchemy has no support for CTEs directly, though of course you can 
construct the query manually and execute and fetch results through 
SQLAlchemy. You *can* get some support for recursive queries 
under SQLAlchemy in https://github.com/marplatense/sqla_hierarchy/ but 
be warned, that project is ... youthful :)


Regards,

- Gulli

--
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/-/g7-7S4mBC3wJ.

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.


--
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] SA Unicode and SQLite

2011-08-02 Thread Mark Erbaugh
I'm trying to follow the instructions in the SA docs regarding Unicode and 
SQLite.  I've declared all my character fields as either Unicode or 
UnicodeText.  When populating the data, I specify strings as unicode strings 
(u'string'), but I'm still getting an warning: SAWarning Unicode type received 
non-unicode bind parameter, when I initially populate the database.  On the 
next line, it reports param.append(processors[key](compiled_params[key])).  Is 
this supposed to be telling me what the errant bind parameter is?

I've turned on echo and looking at the queries and parameters, all the 
character parameters are specified as unicode strings, except for the dates 
which are given like '2011-08-02'.  Are the dates what's causing the 
non-unicode bind parameter warning?

I'm using SQLAlchemy 0.7.1, with Python 2.7.2

Thanks,
Mark

-- 
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] SA Unicode and SQLite

2011-08-02 Thread Michael Bayer

On Aug 2, 2011, at 6:35 PM, Mark Erbaugh wrote:

 I'm trying to follow the instructions in the SA docs regarding Unicode and 
 SQLite.  I've declared all my character fields as either Unicode or 
 UnicodeText.  When populating the data, I specify strings as unicode strings 
 (u'string'), but I'm still getting an warning: SAWarning Unicode type 
 received non-unicode bind parameter, when I initially populate the database.  
 On the next line, it reports 
 param.append(processors[key](compiled_params[key])).  Is this supposed to be 
 telling me what the errant bind parameter is?
 
 I've turned on echo and looking at the queries and parameters, all the 
 character parameters are specified as unicode strings, except for the dates 
 which are given like '2011-08-02'.  Are the dates what's causing the 
 non-unicode bind parameter warning?
 
 I'm using SQLAlchemy 0.7.1, with Python 2.7.2

Set the warnings filter to error and send off a stack trace, that will show 
exactly where the offending statement is (its not impossible that its within 
SQLA too).

import warnings
warnings.simplefilter(error)

http://docs.python.org/library/warnings.html

-- 
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] misleading docs on logging

2011-08-02 Thread Chris Withers

Hi All,

Just me or does this:

http://www.sqlalchemy.org/docs/core/engines.html?highlight=logging#configuring-logging

...imply that to get pool logging you just need to do:

import logging
logging.getLogger('sqlalchemy.pool').setLevel(logging.DEBUG)

Whereas, in fact, you need to do:

import logging
logging.getLogger('sqlalchemy').setLevel(logging.INFO)
logging.getLogger('sqlalchemy.pool').setLevel(logging.DEBUG)
logging.getLogger('sqlalchemy.engine').setLevel(logging.WARNING)
logging.getLogger('sqlalchemy.mapper').setLevel(logging.WARNING)

...to get just the pool logging, and then, with 0.6 at least, you find 
that things like checking connections in and out of the pool don't 
appear to be logged.


Am I missing something here?

cheers,

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 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] SA Unicode and SQLite

2011-08-02 Thread Mark Erbaugh

On Aug 2, 2011, at 6:50 PM, Michael Bayer wrote:

 
 On Aug 2, 2011, at 6:35 PM, Mark Erbaugh wrote:
 
 I'm trying to follow the instructions in the SA docs regarding Unicode and 
 SQLite.  I've declared all my character fields as either Unicode or 
 UnicodeText.  When populating the data, I specify strings as unicode strings 
 (u'string'), but I'm still getting an warning: SAWarning Unicode type 
 received non-unicode bind parameter, when I initially populate the database. 
  On the next line, it reports 
 param.append(processors[key](compiled_params[key])).  Is this supposed to be 
 telling me what the errant bind parameter is?
 
 I've turned on echo and looking at the queries and parameters, all the 
 character parameters are specified as unicode strings, except for the dates 
 which are given like '2011-08-02'.  Are the dates what's causing the 
 non-unicode bind parameter warning?
 
 I'm using SQLAlchemy 0.7.1, with Python 2.7.2
 
 Set the warnings filter to error and send off a stack trace, that will show 
 exactly where the offending statement is (its not impossible that its within 
 SQLA too).
 
 import warnings
 warnings.simplefilter(error)
 
 http://docs.python.org/library/warnings.html
 

Thanks, that did the trick.

Mark

-- 
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] misleading docs on logging

2011-08-02 Thread Michael Bayer

On Aug 2, 2011, at 7:13 PM, Chris Withers wrote:

 Hi All,
 
 Just me or does this:
 
 http://www.sqlalchemy.org/docs/core/engines.html?highlight=logging#configuring-logging
 
 ...imply that to get pool logging you just need to do:
 
 import logging
 logging.getLogger('sqlalchemy.pool').setLevel(logging.DEBUG)
 
 Whereas, in fact, you need to do:
 
 import logging
 logging.getLogger('sqlalchemy').setLevel(logging.INFO)
 logging.getLogger('sqlalchemy.pool').setLevel(logging.DEBUG)
 logging.getLogger('sqlalchemy.engine').setLevel(logging.WARNING)
 logging.getLogger('sqlalchemy.mapper').setLevel(logging.WARNING)
 
 ...to get just the pool logging, and then, with 0.6 at least, you find that 
 things like checking connections in and out of the pool don't appear to be 
 logged.
 
 Am I missing something here?

Not sure if you're missing anything but I certainly am.   sqlalchemy.pool is 
the only logger involved with pool logging and I'm having a hard time imagining 
how you've arrived at your result !

Here is a demo:

from sqlalchemy import create_engine

import logging
logging.basicConfig()
logging.getLogger(sqlalchemy.pool).setLevel(logging.DEBUG)

e = create_engine('sqlite://')
c = e.connect()
c.close()

here is the output with 0.6:

classics-MacBook-Pro:sa06 classic$ python test.py
DEBUG:sqlalchemy.pool.SingletonThreadPool.0x...2570:Created new connection 
sqlite3.Connection object at 0x2dfc58
DEBUG:sqlalchemy.pool.SingletonThreadPool.0x...2570:Connection 
sqlite3.Connection object at 0x2dfc58 checked out from pool
DEBUG:sqlalchemy.pool.SingletonThreadPool.0x...2570:Connection 
sqlite3.Connection object at 0x2dfc58 being returned to pool






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

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