Skip to content

Fix issue where a detached relationship on RoleAssignment#1841

Merged
shangyian merged 2 commits intoDataJunction:mainfrom
shangyian:fix-role-assignments-bug
Mar 8, 2026
Merged

Fix issue where a detached relationship on RoleAssignment#1841
shangyian merged 2 commits intoDataJunction:mainfrom
shangyian:fix-role-assignments-bug

Conversation

@shangyian
Copy link
Copy Markdown
Collaborator

Summary

The bug: DJHTTPBearer and get_auth_context each get their own database session via Depends(get_session). The User is loaded with selectinload(role_assignments) in the bearer's session (S1), stored in request.state.user, then S1 closes, which expunges all its ORM objects, clearing the eagerly-loaded collection from the instance's state. When get_auth_context runs in session S2 and calls list(user.role_assignments), the User is detached and the collection is gone, triggering the lazy load error.

The fix is for get_effective_assignments to issue a fresh select for RoleAssignment filtered by user id using the current session. It never touches the detached relationship at all.

Test Plan

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

Deployment Plan

@shangyian shangyian added the bug Something isn't working label Mar 7, 2026
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 7, 2026

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit 58c82f4
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/69adcb2c99448b00080adb29

…arate sessions being used to load the auth context and bearer session) was causing errors
@shangyian shangyian force-pushed the fix-role-assignments-bug branch from 2a4b531 to 58c82f4 Compare March 8, 2026 19:16
@shangyian shangyian marked this pull request as ready for review March 8, 2026 19:17
@shangyian shangyian merged commit 80a1c22 into DataJunction:main Mar 8, 2026
17 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