spanner: add better support for reading a row that may not exist #10031
Labels
api: spanner
Issues related to the Spanner API.
priority: p2
Moderately-important priority. Fix may not be included in next release.
type: question
Request for information or clarification. Not an issue.
Is your feature request related to a problem? Please describe.
ReadRow
documentation states that it returns a NotFound error if the row is not found.However, we've discovered that there are other scenarios where NotFound can be returned that aren't documented, such as when a column is not found. This was difficult to find given we had added special logic for handling NotFound to return
nil, nil
instead. This thus makes handling the typical code path of doing a "FetchOne", then checking if it exists, extra hard (as not only is it returning an error instead of just nil, but the error is ambiguous).Describe the solution you'd like
Ideally,
ReadRow
would not fail simply on not finding the entity. It would fail when there's a real error (not finding the row is arguably nominal and typically handled by returning null or equivalent). A variant likeReadRowOrNil
would be ideal.Otherwise, provide some robust way to determine when the row is not found vs when there's an actual error.
Another thing to consider is whether a schema issue like a missing column should be treated as NotFound, as that is not intuitive to me, since my assumption is that the "NotFound" pertains to the Row, not some underlying schema detail.
Describe alternatives you've considered
Matching on the string message e.g. "row not found", which is not ideal and preferable to avoid.
Additional context
NA
The text was updated successfully, but these errors were encountered: