Skip to content
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

recompute OWSRegistry on demand to avoid caching issues with db-session #111

Merged
merged 2 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changes
Unreleased
==========

Changes:

* Enforce regeneration of the ``OWSRegistry`` object on each request to avoid incorrect handling by adapters that
require the new transaction or refreshed database session state each time.

0.6.1 (2021-10-27)
==================

Expand Down
9 changes: 8 additions & 1 deletion twitcher/owsregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,11 @@ def includeme(config):
def owsregistry(request):
adapter = get_adapter_factory(request)
return adapter.owsregistry_factory(request)
config.add_request_method(owsregistry, reify=True)

# In case the adapter employs caching or other per-request/session dependent transaction details, we must ensure
# to regenerate the owsregistry object each time since the service-store it provides (amongst other things),
# only initializes the request once instead of per-request method calls.
# For example, 'request.owsregistry.get_service_by_name' will call 'ServiceStore.fetch_by_name' with
# the 'ServiceStore' initialized and stored with the first ever request (if reify=True). All following service
# operations would employ the stored database session contained within this request.
config.add_request_method(owsregistry, reify=False, property=True)