Repository navigation
Fix SQLAlchemy query cache collisions for bound parameters - #8886
Open
gorkadabo1 wants to merge 1 commit into
Open
gorkadabo1 wants to merge 1 commit into
gorkadabo1 wants to merge 1 commit into
Conversation
gorkadabo1
force-pushed
the
fix/sql-bound-parameter-cache-8877
branch
from
October 23, 2026 10:41
d6631a2 to
04ec1bd
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.
What does this PR do?
Fixes #8877
Dataset.from_sql()can silently return incorrect cached rows when two SQLAlchemy queries differ only in their bound parameter values. The existing cache identity includes the compiled SQL placeholders but not their values, causing queries with differentWHERE,LIMIT/OFFSET, orINparameters to share a cache.This change includes the compiled SQL and its effective bound parameters when calculating the configuration hash.
It also handles:
memoryviewvalues, including nested structures.Raw SQL string behavior remains unchanged.
Validation
Added 24 regression tests for cache collisions, cache reuse with equivalent queries, parameter overrides, callable parameters, binary values, and compatibility.
make qualityandgit diff --checkpassed.Compatibility
SQLAlchemy
Selectablequeries get new cache keys, so they won't reuse potentially incorrect existing caches. Previously saved incorrect datasets need to be regenerated. Cache reuse is intentionally skipped for callable parameters that cannot be resolved. Some statement-level callable overrides in SQLAlchemy 2.1 may also miss cache reuse, even when it would be safe.This fix is independent of #8752, which modifies the same method for connection handling. Both changes were tested together successfully (47 SQL tests passed), although merging them may require resolving the overlapping code. Other SQL dialects were tested by compiling queries, but not against live databases.