Skip to content

fix(datastore): Handling nil slices in save and query - #8043

Merged
bhshkh merged 3 commits into
googleapis:mainfrom
bhshkh:datastore-nil-slices
Jun 12, 2023
Merged

bhshkh merged 3 commits into
googleapis:mainfrom
bhshkh:datastore-nil-slices

Conversation

@bhshkh

@bhshkh bhshkh commented Jun 4, 2023

Copy link
Copy Markdown
Contributor

Issue: #5760
Cause:
If an entity e.g. {'Description': 'Buy milk'} is being queried into a struct e.g. task := Task{Description: "Some description", Done: false, Slice: []int{11, 12, 13, 14, 15}}, then the fields not existing in entity retrieved from datastore are left untouched i.e. it.Next(&task) will populate task variable to Task{Description: "Buy milk", Done: false, Slice: []int{11, 12, 13, 14, 15}}

Any nil slice property in put call to datastore gets ignored i.e. as if the property does not exist for that entity. So, while retrieving nil slices, they don't get populated in the struct.

Fix: Write nil slices as null values to datastore similar to nodejs and python client libraries. Special handling for nil slices while querying datastore.

@bhshkh
bhshkh requested review from a team June 4, 2023 19:51
@product-auto-label product-auto-label Bot added the size: s Pull request size is small. label Jun 4, 2023
@bhshkh
bhshkh requested a review from enocom June 6, 2023 07:28
@bhshkh
bhshkh enabled auto-merge (squash) June 10, 2023 02:34
@bhshkh bhshkh changed the title fix(datstore): Handling nil slices in save and query fix(datastore): Handling nil slices in save and query Jun 10, 2023
@bhshkh
bhshkh merged commit 36f01e9 into googleapis:main Jun 12, 2023
bhshkh added a commit to bhshkh/google-cloud-go that referenced this pull request Jun 13, 2023
bhshkh added a commit that referenced this pull request Jun 13, 2023
xwkuang5 added a commit to xwkuang5/google-cloud-go that referenced this pull request Jun 13, 2023
…nto agg-add-trace

* 'agg-add-trace' of github.com:xwkuang5/google-cloud-go:
  Fix formating.
  chore(firestore): Add bloom filter related comments (googleapis#8079)
  fix(firestore): Cleanup integration test resources (googleapis#8057)
  fix(datastore): Handling nil slices in save and query (googleapis#8043)
@bhshkh
bhshkh deleted the datastore-nil-slices branch June 22, 2023 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

datastore: Previous value is returned for overwritten key when dst not zero-valued

3 participants

⌂ 换网址