This is a super common complaint from people and it doesn't have a single definitive solution. There are a couple handy tricks:
1. If your classmethod receives any managed objects, you can get a reference to the session from the object itself. For example ``sqlalchemy.orm.object_session(user)``.
2. The easy answer when the above doesn't work is to pass the dbsession into the class method.
After this - if still not satisfied - are some hacky things you can do:
1. Stop using classmethod approaches and instead put in a real service layer. This has tons of benefits, see something like pyramid_services for more information about this. This approach will allow you to bind the whole service to a dbsession, and no longer need to pass it around at all.
2. Define a helper to grab the session from the request threadlocal. Something like ``get_current_dbsession = lambda: get_current_request().dbsession``. Then import that and use it via ``dbsession = get_current_dbsession()``.
The threadlocal approach above has some downsides but is still better than using a scoped session. Allowing the request to seep into and infect your data model is a little wonky and makes your model code less reusable outside of Pyramid. Even if you are okay with that, something like ``get_current_dbsession().query()`` is going to be better than ``scoped_session.query()`` because it's more explicitly a value that changes over time versus the magic scoped session object proxy.
In my own apps I use all the approaches mentioned above except the threadlocal one.
- Michael