-
Notifications
You must be signed in to change notification settings - Fork 34
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
deregister zope.sqlalchemy.register() #9
Labels
Comments
robertknight
added a commit
to hypothesis/h
that referenced
this issue
Jan 9, 2018
`zope.sqlalchemy.register` adds a set of event listeners to a session which trigger population of an internal `id(session) => state` map whenever a session becomes dirty. This map is usually cleared when the DB transaction is committed as a result of the transaction manager being committed or aborted at the end of a web request by pyramid_tm. If however `request.session` is accessed outside of pyramid_tm's tween and DB changes are made, the event listeners will fire and references to the session's ID will be left in the internal _SESSION_STATE map when the request ends. This commit adds a check for a non-empty map at the end of a request and logs a warning, to help track down causes of DB writes that are causing the issue, it then cleans up the dirty state. Unfortunately there are no public APIs for deregistering a session [1], so we clear zope.sqlalchemy's private internal map directly. [1] zopefoundation/zope.sqlalchemy#9
robertknight
added a commit
to hypothesis/h
that referenced
this issue
Jan 9, 2018
`zope.sqlalchemy.register` adds a set of event listeners to a session which trigger population of an internal `id(session) => state` map whenever a session becomes dirty. This map is usually cleared when the DB transaction is committed as a result of the transaction manager being committed or aborted at the end of a web request by pyramid_tm. If however `request.session` is accessed outside of pyramid_tm's tween and DB changes are made, the event listeners will fire and references to the session's ID will be left in the internal _SESSION_STATE map when the request ends. This commit adds a check for a non-empty map at the end of a request and logs a warning, to help track down causes of DB writes that are causing the issue, it then cleans up the dirty state. Unfortunately there are no public APIs for deregistering a session [1], so we clear zope.sqlalchemy's private internal map directly. [1] zopefoundation/zope.sqlalchemy#9
robertknight
added a commit
to hypothesis/h
that referenced
this issue
Jan 9, 2018
`zope.sqlalchemy.register` adds a set of event listeners to a session which trigger population of an internal `id(session) => state` map whenever a session becomes dirty. This map is usually cleared when the DB transaction is committed as a result of the transaction manager being committed or aborted at the end of a web request by pyramid_tm. If however `request.session` is accessed outside of pyramid_tm's tween and DB changes are made, the event listeners will fire and references to the session's ID will be left in the internal _SESSION_STATE map when the request ends. This commit adds a check for a non-empty map at the end of a request and logs a warning, to help track down causes of DB writes that are causing the issue, it then cleans up the dirty state. Unfortunately there are no public APIs for deregistering a session [1], so we clear zope.sqlalchemy's private internal map directly. [1] zopefoundation/zope.sqlalchemy#9
robertknight
added a commit
to hypothesis/h
that referenced
this issue
Jan 9, 2018
`zope.sqlalchemy.register` adds a set of event listeners to a session which trigger population of an internal `id(session) => state` map whenever a session becomes dirty. This map is usually cleared when the DB transaction is committed as a result of the transaction manager being committed or aborted at the end of a web request by pyramid_tm. If however `request.session` is accessed outside of pyramid_tm's tween and DB changes are made, the event listeners will fire and references to the session's ID will be left in the internal _SESSION_STATE map when the request ends. This commit adds a check for a non-empty map at the end of a request and logs a warning, to help track down causes of DB writes that are causing the issue, it then cleans up the dirty state. Unfortunately there are no public APIs for deregistering a session [1], so we clear zope.sqlalchemy's private internal map directly. [1] zopefoundation/zope.sqlalchemy#9
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There should be a deregister() counterpart to the new zope.sqlalchemy.register() function. It will be useful in contexts where you have to use the same Session but with different transactional behaviours.
For instance, depending on the situation, you may need to (dynamically) set keep_session=False or keep_session=True. This is very easy to accomplish using the old SQLAlchemy extension system. You just use Session.configure. On the other hand, using the new register() function, there is no way to do it.
I think that sqlalchemy.event.remove should do the trick.
http://docs.sqlalchemy.org/en/rel_0_9/core/event.html#sqlalchemy.event.remove
The text was updated successfully, but these errors were encountered: