On Monday, January 6, 2020 at 4:03:19 PM UTC-5, Kate Boelhauf wrote:
>
> This is insanely helpful - thank you Michael.  I'm going to pass the 
> dbsession into the class method for now but look into a service layer.  
>

A few years ago I adopted the pattern of passing Pyramid's `request` object 
into all class methods - and pretty much everything else - as the first 
argument representing the "context".  From that, I can grab my active core 
database session via `request.dbsession`.  If I need to override with an 
explicit dbSession, I pass in a dbsession kwarg or will inspect the object 
using `sqlalchemy.orm.object_session(user)` as Michael suggested.

At one point I passed in the dbSession, but I found myself with a chunks of 
code that expected a dbSession and chunks that expected a request.  
Standardizing everything to a request saved a lot of headaches down the 
line for me.

>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/89768643-b6bc-4458-b0ee-b8b8f3d57b54%40googlegroups.com.

Reply via email to