GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp
SpannerTemplate#update ambiguously requires primary keys in includeProperties
- Dominant language
- Java
- Stars
- 551
- Forks
- 349
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 14
Description
**Is your feature request related to a problem? Please describe.**
I was getting a `NOT_FOUND` error from the spanner emulator because I was not including the primary keys of my POJO in `includeProperties` in `SpannerTemplate#update(Object object, Set includeProperties)`. Documentation (primarily [this](https://googlecloudplatform.github.io/spring-cloud-gcp/reference/html/index.html#partial-update)) does not say this is necessary. Since primary keys are immutable, it implies that primary keys should not be in `includeProperties`.
Setup
Spring Cloud Spanner
- `com.google.cloud:spring-cloud-gcp-dependencies:4.5.0`
- `com.google.cloud:spring-cloud-gcp-starter-data-spanner` (inherited version)
Cloud Spanner Emulator
- `gcr.io/cloud-spanner-emulator/emulator:latest`
**Describe the solution you'd like**
Require that primary keys be defined - not null - on the update POJO but not in `includeProperties`. I think the easiest way to accomplish this is to add the primary keys to `includeProperties` within `SpannerTemplate#update` or `SpannerMutationFactoryImpl#update`
**Describe alternatives you've considered**
Clearly document in Spring Cloud GCP that primary keys must be in `includeProperties`, ideally in both the inline docs and API docs.
**Additional context**
The specific error is `io.grpc.StatusRuntimeException: NOT_FOUND: Table users: Row {String(NULL)} not found.`
Example of `Mutation#toString` created by Spring Cloud Spanner with and without putting the primary keys in `includeProperties`:
- with: `[update(users{user_id=61c71f46-a11f-4340-914d-23b54a02ccb3,credits=243498372})]`
- without: `[update(users{credits=206320900})]`
Contributor guide
Research direction
Start with SpannerTemplate#update(Object, Set includeProperties) and SpannerMutationFactoryImpl#update, then compare the generated mutations shown in the issue with the partial-update documentation. Check how primary keys are handled when they are omitted, and update the implementation or documentation so the required behavior is explicit and testable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- google-cloud, java, spring
- Domain
- databases, documentation
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100