Skip to content

fix: remove stateful instance caching from endpoints for thread-safety#942

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/remove-stateful-caching
Draft

fix: remove stateful instance caching from endpoints for thread-safety#942
Copilot wants to merge 3 commits into
mainfrom
copilot/remove-stateful-caching

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

GenericListGetEndpoint held a self._cache dict mutated on every list() call, creating race conditions and cross-request data leaks when the SDK is shared across threads (FastAPI, Airflow workers, etc.).

Changes

Removed caching infrastructure

  • self._cache, _get_local_cache(), _update_local_cache(), _check_cache_hit() deleted from GenericListGetEndpoint
  • _enable_cache class attribute removed from EndpointABC and EndpointProtocol
  • refresh parameter removed from _list_sync, _list_async, _prepare_list_request, and ListEndpointProtocol
  • cache, cached_result, has_filters fields removed from ListRequestState

Endpoint cleanup

  • _enable_cache = True removed from StudiesEndpoint, FormsEndpoint, VariablesEndpoint, IntervalsEndpoint

Downstream callers updated

  • FilterGetOperation.execute_sync/execute_async: dropped refresh=True from list calls
  • validation/cache.py (SchemaValidator, AsyncSchemaValidator, SchemaCache): dropped refresh=True from all variables.list() / variables.async_list() calls

Docs

  • docs/caching.rst: replaces the "Endpoint Caches" section with a note that endpoint caching has been removed; directs consumers to application-layer solutions (cachetools, httpx-cache, framework caches)

Every list() / async_list() call now performs a fresh HTTP request. Callers that relied on refresh=True to bypass the cache simply pass no refresh argument.

Removes self._cache and all associated caching logic from GenericListGetEndpoint.
Every list()/async_list() call now performs a fresh API request, eliminating
race conditions and cross-request data leaks in concurrent environments.

- Remove self._cache, _get_local_cache, _update_local_cache, _check_cache_hit
- Remove refresh parameter from _list_sync, _list_async, _prepare_list_request
- Simplify ListRequestState struct (remove cache, cached_result, has_filters fields)
- Remove _enable_cache attribute from EndpointABC, EndpointProtocol
- Remove refresh=True from FilterGetOperation and validation/cache.py list calls
- Remove _enable_cache = True from studies, forms, variables, intervals endpoints
- Update all tests to reflect stateless behavior
- Update docs/caching.rst to document removal of native endpoint caching

Agent-Logs-Url: https://github.com/fderuiter/imednet-python-sdk/sessions/372392a9-115d-44c0-ba22-f82f5556f061

Co-authored-by: fderuiter <127706008+fderuiter@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove stateful instance caching from endpoints fix: remove stateful instance caching from endpoints for thread-safety May 15, 2026
Copilot AI requested a review from fderuiter May 15, 2026 18:45
@fderuiter
Copy link
Copy Markdown
Owner

@copilot Job 76252924590 is failing in the Quality & Security job, specifically the Enforce Style step in .github/workflows/main.yml.

Failure:

would reformat tests/unit/test_core_endpoint_operations.py

Oh no! 💥 💔 💥
1 file would be reformatted, 311 files would be left unchanged.

The workflow runs:

poetry run black --check .
poetry run isort --check --profile black .

So the issue is not a test failure; it is a Black formatting failure in:

tests/unit/test_core_endpoint_operations.py

The likely offending line is this long assertion near the end of the file:

client.post.assert_called_once_with(
    "/create", json=[{"field1": "val1"}], headers={HEADER_EMAIL_NOTIFY: "user@example.com"}
)

Black would reformat it to:

client.post.assert_called_once_with(
    "/create",
    json=[{"field1": "val1"}],
    headers={HEADER_EMAIL_NOTIFY: "user@example.com"},
)

Apply that change in tests/unit/test_core_endpoint_operations.py.

You can also let Black fix it automatically:

poetry run black tests/unit/test_core_endpoint_operations.py

Then verify locally with:

poetry run black --check .
poetry run isort --check --profile black .

No workflow change is needed; the job is correctly enforcing formatting.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 15, 2026

@copilot Job 76252924590 is failing in the Quality & Security job, specifically the Enforce Style step in .github/workflows/main.yml.

Failure:
...

Fixed in 69ac685. Black collapsed the two short assert_called_once_with calls from multi-line to single-line form, and expanded the long client.post.assert_called_once_with(...) call into the trailing-comma style it requires.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Remove stateful instance caching from endpoints (Thread-Safety)

2 participants