-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Singleton per request object #11
Comments
I see what you're saying. Ideally we would use the original |
We can certainly make that change. I'm not sure it's entirely obvious how to go about it right now, but if you want to investigate please feel free to open a PR with a fix or even just add a test case to the test suite. |
mmerickel
added a commit
that referenced
this issue
Feb 3, 2016
avoid making new services per specific-context when the service is registered for a more general interface Fixes #11
mmerickel
added a commit
that referenced
this issue
Feb 3, 2016
avoid making new services per specific-context when the service is registered for a more general interface Fixes #11
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One issue I ran into with your dbsession service example (that uses a service factory) is the following:
When looking for the service different sessions are returned depending on the context. This is by design. Citing the documentation:
Having different DB session in one request is quite ugly and I can think of no use case for it. How did I end up with different contexts? By using the request object outside a view function invoked directly with pyramid.threadlocal.get_current_request . In that case the context is None.
This example by Jon Rosebaugh - What the Zope Transaction Manager Means To Me (and you) would work but I wanted to use pyramid_services (for consistency, because I'm already using it in other parts of the application).
I'm aware that this might not be the place for this since it classifies more as a question than an issue, but you could at least fix the example to be more clear that
will return different sessions depending on the request context.
My workaround is to always pass context=None:
Is there a simpler solution (e.g. a singleton per request)? register_service() would register a singleton object for the whole application, but I do want a different DB session for every request.
The text was updated successfully, but these errors were encountered: