On 7/28/15 8:11 AM, Chris Withers wrote:
Hi All,

I'm looking to use a session as a context manager, I've found session_scope here:

http://docs.sqlalchemy.org/en/latest/orm/session_basics.html#when-do-i-construct-a-session-when-do-i-commit-it-and-when-do-i-close-it

...but is there anything in the core?

I find of expected a session to do what session_scope does when used like so:

with Session() as session:

OK I've spend 10 minutes deciphering this, i think by "core" you mean, "in SQLAlchemy ORM itself", note SQLAlchemy has a thing called Core that is specifically not the ORM.


The transaction on a session is a context manager:


with session.transaction:
    # foo


as is begin(), which is what I see a lot:

with session.begin():

the above has already led to all kinds of code in Openstack that I am now struggling to get them to change everywhere because it is way too verbose (because they call it everywhere, in every function, meaning they use a zillion transactions); I made them an application-specific context system they should be using.

That is, even the slightest bit of "framework-ish" thing in SQLAlchemy leads people to not seek using the best solution for their needs, and I've always tried to encourage people to write / use the framework-ish features that work best for them. Hence the example in the docs, where note I have the comments: "this is a **better** (but not the only) way to do it", "another way (but again *not the only way*) to do it". I really want people to learn to write code that suits their use case. There are also a ton of SQLAlchemy-frameworks on pypi - if these framework patterns are really so obvious then some of those frameworks should be amazing.












...

If I knocked up a pull request to make that happen, would it be accepted?





cheers,

Chris


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to