fix: add sync fallback for async adapter reads (read/list/search)#217
Merged
Conversation
Writes were persisting correctly (async RETURNING check + sync fallback), but all read-path endpoints (read, list, search) still routed through the async adapter whose RLS GUC context is broken — entries committed by the sync fallback are invisible to async reads. - read_entry: try async, fall back to sync if entry not found - list_entries: try async, fall back to sync if result is empty - search_entries: try async, fall back to sync if no results - async_adapter: log warning when tenant account_id contextvar is empty at pool checkout (helps diagnose the RLS context propagation issue) Each fallback logs a warning when the sync adapter finds data the async adapter missed, confirming the RLS context mismatch for investigation.
5f0dc6f to
a73146f
Compare
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
Follow-up to #216 (async write persistence fix). After deploying the write fix, testing revealed:
read(),list(), andsearch()methods return empty results for entries that ARE committed in the databasequalityandhistoryendpoints (which use the sync adapter) correctly return all entriesThis confirms the issue is specifically in the async adapter's RLS GUC context during reads — the
amfs.current_account_idsession variable is likely empty when the async pool checks out connections for read operations, causing RLS policies to hide all entries.Changes
server.py— read/list/search sync fallbacks: Each endpoint now tries the async adapter first, and if it returns empty/None, transparently falls back to the sync adapter. A warning is logged when the sync adapter finds data the async adapter missed, confirming the RLS context mismatch.async_adapter.py— GUC diagnostic logging: The_AsyncTenantRLSConnection.__aenter__now logs a warning when the tenantaccount_idcontextvar is empty at pool checkout, which directly causes the RLS read failure.Evidence from production testing