Yes, a nice simplification.
I'm using it to lazyload attributes for objects that aren't in a
session.  I'm not sure if you pointed me there, I think I found it
myself, but you helped work out the later details...
Our app lives inside a webserver framework that, very appropriately,
in my opinion, only has one session for any given web request.  So,
for our framework, I can safely lazyload related attributes for
transient or detached objects by temporarily setting state.session_id:

def configure_attribute(class_, attr, inst):
    """
    Set up function to be invoked when relations are 'get'ed on
possibly
    transient objects, so we can automatically query these related
objects
    """
    if isinstance(inst.property, RelationshipProperty):
        default_loader = inst.impl.callable_
        def load_value(state, passive):
            if state.session_id is not None:
                # this is persistent or pending, so
                # return default sqla functionality
                return default_loader(state, passive)
            if passive is attributes.PASSIVE_NO_FETCH:
                return attributes.PASSIVE_NO_RESULT
            # session_id is currently None
            state.session_id = DBSession().hash_key
            retval = default_loader(state, passive)
            state.session_id = None
            return retval
        inst.impl.callable_ = load_value

..
..
event.listen(DBEntity, 'attribute_instrument', configure_attribute)


On Dec 26, 12:26 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> On Dec 26, 2011, at 9:07 AM, Kent wrote:
>
> > Documentation for AttributeImpl.callable_ still reads
> >     "optional function which generates a callable based on a parent
> >           instance, which produces the "default" values for a scalar or
> >           collection attribute when it's first accessed, if not present
> >           already."
> > But it seems it is no longer the function which generates a callable, but 
> > rather is the callable itself now, accepting both the state and the passive 
> > parameters.
>
> > It used to be two stages, first callable_ accepts a state and then that 
> > returns a callable which accepted the passive parameter.
>
> yes that was a fabulous simplification of things I'm still very happy about.
>
>
>
> > Can you briefly summarize how this is meant to work now? (I think the doc 
> > string is wrong now??)
>
> docstring is wrong yes.   the callable just receives a state and a passive 
> flag, then loads something for the attribute.    It's just one less level of 
> "callable" and the two that we have in use are LoadDeferredColumns and 
> LoadLazyAttribute in strategies.py.     This also isn't very public API and 
> if I pointed you to this for some previous issue, I'd be curious if I 
> remembered to mention that.....
>
>
>
>
>
>
>
>
>
> > On 12/25/2011 10:31 AM, Michael Bayer wrote:
>
> >> yes a few change names, reconstruct_instance, init_instance, init_failed.
>
> >> On Dec 24, 2011, at 7:42 PM, Kent Bower wrote:
>
> >>> Right.  And reconstruct_instance() was renamed load()?
>
> >>> On 12/24/2011 5:56 PM, Michael Bayer wrote:
> >>>> On Dec 24, 2011, at 10:04 AM, Kent wrote:
>
> >>>>> As the migration guide suggests, I'd like to embrace the events API.
> >>>>> Is mapper event load() invoked at exactly the same place as the
> >>>>> deprecated reconstruct_instance() ?
> >>>> yeah nothing has been moved.   All the places where the internals would 
> >>>> call XXXExtension.xxx_event() were just replaced with 
> >>>> self.dispatch.xxx_event(), and the old Extension classes are invoked via 
> >>>> an adapter to the new system.   All unit tests for the extension system 
> >>>> remain in place and haven't been modified.
>
> >>>>> --
> >>>>> 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 
> >>>>> athttp://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 
> >>> athttp://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 
> > athttp://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.

Reply via email to