Fix concurrent-session crash on GQL DataLoaders#2057
Merged
shangyian merged 2 commits intoDataJunction:mainfrom Apr 25, 2026
Merged
Fix concurrent-session crash on GQL DataLoaders#2057shangyian merged 2 commits intoDataJunction:mainfrom
shangyian merged 2 commits intoDataJunction:mainfrom
Conversation
✅ Deploy Preview for thriving-cassata-78ae72 canceled.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 permittedon a subset of edges.The root cause was that
get_contextwas unconditionally attaching itsDepends(get_session)session torequest.state.test_session, whichsession_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 originalnot 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 viasession_context().Test Plan
Test coverage added for both code paths in test_main.py.
make checkpassesmake testshows 100% unit test coverageDeployment Plan