Re: [sqlalchemy] Inject/Extend an attribute onto all objects in a Session?

2016-10-28 Thread Jonathan Vanasco
yeah, `remove` is just a better way to handle scoped sessions. I should really move to regular sessions like you; I keep forgetting that I have these old legacy scoped sessions for no reason. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To

Re: [sqlalchemy] Inject/Extend an attribute onto all objects in a Session?

2016-10-28 Thread Simon King
> On 28 Oct 2016, at 21:47, Jonathan Vanasco wrote: > > oh great! `session.info["request"]` solved all my problems quite nicely. i > integrated that my pipy sessions manager. > > Simon, thanks. Looking at your code, I recall that `dbsession.remove()` may > be better than

Re: [sqlalchemy] Inject/Extend an attribute onto all objects in a Session?

2016-10-28 Thread Jonathan Vanasco
oh great! `session.info["request"]` solved all my problems quite nicely. i integrated that my pipy sessions manager. Simon, thanks. Looking at your code, I recall that `dbsession.remove()` may be better than `dbsession.close()`

Re: [sqlalchemy] inspect a scalar relationship property when it is loaded

2016-10-28 Thread mike bayer
On 10/28/2016 11:55 AM, Kent Bower wrote: The load() event would also capture if it were subqueryload()ed, right? any eagerload. And overriding Query.__iter__ wouldn't catch the cases where the scalar is a "use_get" lookup that was already in session.identity_map... right, would need

Re: [sqlalchemy] inspect a scalar relationship property when it is loaded

2016-10-28 Thread Kent Bower
The load() event would also capture if it were subqueryload()ed, right? And overriding Query.__iter__ wouldn't catch the cases where the scalar is a "use_get" lookup that was already in session.identity_map... No good way to intercept attributes.set_committed() for that, is there? On Fri, Oct

Re: [sqlalchemy] inspect a scalar relationship property when it is loaded

2016-10-28 Thread mike bayer
On 10/28/2016 10:48 AM, Kent wrote: @validates and 'set' attribute events will only fire when the /user/ sets a property (setattr), not when initially loaded by the orm. Is there a way to intercept (for inspection) a scalar relationship property instance when it is loaded? I don't think the

Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-28 Thread mike bayer
I've changed the assertions to all expect "3" items since assertions should illustrate what's expected to happen (this again communicates to me what the problem is). Applying expire() to all three (plus reassignment in the first case) allows them all to work. If you don't expire the

[sqlalchemy] inspect a scalar relationship property when it is loaded

2016-10-28 Thread Kent
@validates and 'set' attribute events will only fire when the *user* sets a property (setattr), not when initially loaded by the orm. Is there a way to intercept (for inspection) a scalar relationship property instance when it is loaded? I don't think the 'load' event will work because I

Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-28 Thread Colton Allen
from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() atob = Table( 'atob', Base.metadata, Column('aid', ForeignKey('a.id'), primary_key=True), Column('bid', ForeignKey('b.id'), primary_key=True) )

Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-28 Thread mike bayer
On 10/28/2016 09:13 AM, Colton Allen wrote: Okay I see. That does remove the error. But I am having trouble saving the relationship. Check the example code. It is much clearer than I am. I can't tell you why the code works or doesn't, at this level I need to run it. I will re-assemble

Re: [sqlalchemy] Creating a transient model with a many-to-many relationship

2016-10-28 Thread Colton Allen
Okay I see. That does remove the error. But I am having trouble saving the relationship. Check the example code. It is much clearer than I am. If I query a new set of items or specify an item model instance it will save perfectly. But all of the instances in the instrumented list will not

Re: [sqlalchemy] Inject/Extend an attribute onto all objects in a Session?

2016-10-28 Thread Simon King
On Fri, Oct 28, 2016 at 3:19 AM, mike bayer wrote: > > > On 10/27/2016 09:41 PM, Jonathan Vanasco wrote: >> >> I have an edge-case in a few situations where, within an @property of a >> SqlAlchemy object, I need to know the current active web-request/context. >> >> I'm