fix(cross_shard_disabled): provide more specific error msg when dealing with unknown sharding key - #1365
Open
jkaczman wants to merge 5 commits into
Open
fix(cross_shard_disabled): provide more specific error msg when dealing with unknown sharding key#1365jkaczman wants to merge 5 commits into
jkaczman wants to merge 5 commits into
Conversation
…ng with unknown sharding key
levkk
reviewed
Aug 14, 2026
Co-authored-by: Lev Kokotov <levkk@users.noreply.github.com>
levkk
reviewed
Aug 14, 2026
| let query = context.client_request.query()?; | ||
| let error = ErrorResponse::cross_shard_disabled(query.as_ref().map(|q| q.query())); | ||
|
|
||
| let error = if let Some(sharding_key) = context.params.get("pgdog.sharding_key") |
Collaborator
There was a problem hiding this comment.
I think this is fine for now. A better solution could be to check this inside the parser:
- If it returns
Shard::All - and
pgdog.sharding_keyis set in params (those are available in the context, see ) - and cross-shard queries are disabled (this may be currently missing from the context but can be easily added I think: )
then the parser can return this error, which we can catch and send to the client.
The reason this is better is because it avoids connecting to Postgres when we know we can't serve that query because of the missing sharding key mapping.
Collaborator
There was a problem hiding this comment.
Another reason why the parser could be a better place for this is because it'll also catch the comment directive:
/* pgdog_sharding_key: 25 */ SELECT * FROM users;while this check will only catch the pgdog.sharding_key SET parameter.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
jkaczman
force-pushed
the
jk-unknown-sharding-key-error
branch
2 times, most recently
from
August 14, 2026 21:10
bcc4437 to
a8a56ce
Compare
jkaczman
force-pushed
the
jk-unknown-sharding-key-error
branch
from
August 14, 2026 21:12
a8a56ce to
6c8dbac
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.
Provides a specific error message "unknown sharding key was specified" as opposed to "cross-shard queries are disabled" when a query:
Fixes #1163