[sqlalchemy] Re: post-populate extension (2)

2008-03-26 Thread Rick Morrison
Also be aware that the API to populate_instance() has changed (ironically,
the very thing that I was worrying about in the thread)

Update this:
def populate_instance(self, mapper, selectcontext, row, instance,
identitykey, isnew):
if isnew:
mapper.populate_instance(selectcontext, instance, row,
identitykey, isnew)
instance.onload()
return None
return EXT_PASS


to this:

def populate_instance(self, mapper, selectcontext, row, instance,
**kwargs):
if kwargs.get('isnew') and hasattr(instance, 'onload'):
mapper.populate_instance(selectcontext, instance, row, **kwargs)
instance.onload()
return None
return EXT_CONTINUE


On Tue, Mar 25, 2008 at 12:57 PM, Michael Bayer [EMAIL PROTECTED]
wrote:


 we have a new hook that will be coming soon called something like
 __reconstitute__(), which will be called on instances after they've
 been created and had their initial population from the result row.
 Note that eagerly-loaded collections might not be fully loaded at this
 stage.

 at the moment the populate_instance() hook is what works in the
 current version of 0.4.

 On Mar 25, 2008, at 7:05 AM, Nebur wrote:

 
  I'm going to post-populate an instance, and there's a thread which is
  exactly about my question but fairly old:
 
 
 http://groups.google.de/group/sqlalchemy/browse_thread/thread/7467f8e9d86b1749/
 
  Is there a post_populate hook in the current SA 0.4.x, or is Ricks way
  (using populate_instance) still the best ?
  Ruben
 
  


 


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



[sqlalchemy] Re: post-populate extension (2)

2008-03-25 Thread Michael Bayer

we have a new hook that will be coming soon called something like  
__reconstitute__(), which will be called on instances after they've  
been created and had their initial population from the result row. 
Note that eagerly-loaded collections might not be fully loaded at this  
stage.

at the moment the populate_instance() hook is what works in the  
current version of 0.4.

On Mar 25, 2008, at 7:05 AM, Nebur wrote:


 I'm going to post-populate an instance, and there's a thread which is
 exactly about my question but fairly old:

 http://groups.google.de/group/sqlalchemy/browse_thread/thread/7467f8e9d86b1749/

 Is there a post_populate hook in the current SA 0.4.x, or is Ricks way
 (using populate_instance) still the best ?
 Ruben

 


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



[sqlalchemy] Re: post-populate extension

2007-01-25 Thread Rick Morrison

Ya, the post_populate hook w/b great -- getting the callback to work
was kinda tricky, and I'm worried calling back to internals like that.
Calling signatures often change on internals.

On 1/25/07, Michael Bayer [EMAIL PROTECTED] wrote:

 yup that would be how you can do that right now.

 i mean, I had this vision of SA being used inside of frameworks which
 would provide their own hooks for these kinds of things, i.e. post-
 query etc.  which is why i dont like to add too many hooks *inside*
 unless absolutely necessary.

 but yah if populate_instance() is doing it for you I dont see
 anything wrong with that(did you want a post_populate_instance()
 hook or something like that ?)

 On Jan 24, 2007, at 11:07 PM, Rick Morrison wrote:

 
  What's the best way to perfom a bit of manipulation on a mapper-loaded
  instance just AFTER it's been populated?
 
  Right now I'm using a mapper extension to override populate_instance
  and then calling back to the mapper argument to do the actual
  population, then adding my changes, but is that the best way?
 
  Thx,
  Rick
 
  


 


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



[sqlalchemy] Re: post-populate extension

2007-01-25 Thread Michael Bayer

ok show me how youre doing it and ill see if i should make something  
more solid for that.

On Jan 25, 2007, at 11:52 AM, Rick Morrison wrote:


 Ya, the post_populate hook w/b great -- getting the callback to work
 was kinda tricky, and I'm worried calling back to internals like that.
 Calling signatures often change on internals.

 On 1/25/07, Michael Bayer [EMAIL PROTECTED] wrote:

 yup that would be how you can do that right now.

 i mean, I had this vision of SA being used inside of frameworks which
 would provide their own hooks for these kinds of things, i.e. post-
 query etc.  which is why i dont like to add too many hooks *inside*
 unless absolutely necessary.

 but yah if populate_instance() is doing it for you I dont see
 anything wrong with that(did you want a post_populate_instance()
 hook or something like that ?)

 On Jan 24, 2007, at 11:07 PM, Rick Morrison wrote:


 What's the best way to perfom a bit of manipulation on a mapper- 
 loaded
 instance just AFTER it's been populated?

 Right now I'm using a mapper extension to override populate_instance
 and then calling back to the mapper argument to do the actual
 population, then adding my changes, but is that the best way?

 Thx,
 Rick







 


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



[sqlalchemy] Re: post-populate extension

2007-01-25 Thread Rick Morrison

K, here's a snipppet that shows the populate_instance catch. It's
pretty straightforward, but the way that the hook takes (row,
instance) in that order, while the callback to the mapper takes
(instance, row)  got me thinking about calling back to internals and
API stability.


def populate_instance(self, mapper, selectcontext, row, instance,
identitykey, isnew):
if isnew:
mapper.populate_instance(selectcontext, instance, row,
identitykey, isnew)
instance.onload()
return None
return EXT_PASS

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