Skip to content

Fix concurrent-session crash on GQL DataLoaders#2057

Merged
shangyian merged 2 commits intoDataJunction:mainfrom
shangyian:fix-gql-session
Apr 25, 2026
Merged

Fix concurrent-session crash on GQL DataLoaders#2057
shangyian merged 2 commits intoDataJunction:mainfrom
shangyian:fix-gql-session

Conversation

@shangyian
Copy link
Copy Markdown
Collaborator

@shangyian shangyian commented Apr 25, 2026

Summary

findNodesPaginated (and any GraphQL query whose resolution fires multiple DataLoaders concurrently) was intermittently failing with: This session is provisioning a new connection; concurrent operations are not permitted on a subset of edges.

The root cause was that get_context was unconditionally attaching its Depends(get_session) session to request.state.test_session, which session_context() then handed back to every DataLoader on the request. Concurrent DataLoaders sharing a single AsyncSession raced on connection acquisition; whichever lost raised the error. The original not hasattr(...) guard was a no-op since nothing upstream ever pre-attached the attribute.

The fix gates the attachment on app.dependency_overrides.get(get_session), where only tests register the overrides. In tests, the shared session is still attached so DataLoaders reuse the test transaction. In production, no attribute is set, so each DataLoader opens its own independent session via session_context().

Test Plan

Test coverage added for both code paths in test_main.py.

  • PR has an associated issue: #
  • make check passes
  • make test shows 100% unit test coverage

Deployment Plan

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 25, 2026

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit 10d3b60
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/69ec6adbf843f80008103dd7

@shangyian shangyian changed the title Do not set shared test session in prod Fix concurrent-session crash on GraphQL DataLoaders in production Apr 25, 2026
@shangyian shangyian changed the title Fix concurrent-session crash on GraphQL DataLoaders in production Fix concurrent-session crash on GQL DataLoaders Apr 25, 2026
@shangyian shangyian added the bug Something isn't working label Apr 25, 2026
@shangyian shangyian marked this pull request as ready for review April 25, 2026 07:41
@shangyian shangyian merged commit a934cb9 into DataJunction:main Apr 25, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant