Skip to content

Conversation

@vangent
Copy link
Contributor

@vangent vangent commented Dec 11, 2020

Fixes #2920
Fixes #2791 (I think)

@jba I'm not familiar with those code and am not sure this is correct. Please advise.

The newly added tests panic without the changes in codec.go.

@vangent vangent requested a review from jba December 11, 2020 20:59
@google-cla google-cla bot added the cla: yes Google CLA has been signed! label Dec 11, 2020
if b, ok := d.AsBytes(); ok {
v.SetBytes(b)
if v.Kind() == reflect.Slice {
v.SetBytes(b)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would previously panic with reflect: call of reflect.Value.SetBytes on array Value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for slice is good, but if false I think you want to fall through to the general list-handling code on line 536/551. It should handle copying into arrays of various size, not just the same size. Currently you will not assign if the destination array is a different size, which is a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that does not work. If I let it fall through, the call to d.ListLen() below fails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, keep your code and return an error if the byte array is a different size, maybe with a TODO that it should work like the general array-copying code below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified it to call prepareLen it if it's an array, I think this does the right thing but PTAL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@codecov
Copy link

codecov bot commented Dec 11, 2020

Codecov Report

Merging #2926 (43f1273) into master (e269dcd) will decrease coverage by 0.14%.
The diff coverage is 84.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2926      +/-   ##
==========================================
- Coverage   69.52%   69.37%   -0.15%     
==========================================
  Files         111      111              
  Lines       11500    11557      +57     
==========================================
+ Hits         7995     8018      +23     
- Misses       2850     2884      +34     
  Partials      655      655              
Impacted Files Coverage Δ
docstore/driver/codec.go 91.57% <84.61%> (-0.34%) ⬇️
internal/retry/retry.go 92.30% <0.00%> (-7.70%) ⬇️
runtimevar/filevar/filevar.go 83.87% <0.00%> (-1.08%) ⬇️
pubsub/rabbitpubsub/rabbit.go 79.92% <0.00%> (-0.76%) ⬇️
pubsub/gcppubsub/gcppubsub.go 75.32% <0.00%> (-0.16%) ⬇️
docstore/gcpfirestore/codec.go 72.66% <0.00%> (+0.66%) ⬆️
pubsub/azuresb/azuresb.go 21.60% <0.00%> (+0.80%) ⬆️
docstore/awsdynamodb/codec.go 56.49% <0.00%> (+1.29%) ⬆️
docstore/mongodocstore/codec.go 79.61% <0.00%> (+4.85%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e269dcd...b78dcbd. Read the comment docs.

@vangent vangent changed the title docstore: fixes to improve handling of byte arrays docstore: fixes to improve handling of byte arrays and non-pointer protocol buffers Dec 21, 2020
@vangent vangent requested a review from eliben December 21, 2020 23:07
@vangent vangent assigned eliben and jba and unassigned jba Dec 21, 2020
@vangent vangent mentioned this pull request Jan 16, 2021
if b, ok := d.AsBytes(); ok {
v.SetBytes(b)
if v.Kind() == reflect.Slice {
v.SetBytes(b)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for slice is good, but if false I think you want to fall through to the general list-handling code on line 536/551. It should handle copying into arrays of various size, not just the same size. Currently you will not assign if the destination array is a different size, which is a bug.

@jba
Copy link
Contributor

jba commented Feb 2, 2021

Thanks for dealing with this, Robert. I missed my mention on the original issue.

@vangent
Copy link
Contributor Author

vangent commented Feb 3, 2021

Thanks for the review @jba, PTAL.

@vangent vangent merged commit c11908e into google:master Feb 3, 2021
@vangent vangent deleted the mongoarray branch February 3, 2021 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Google CLA has been signed!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docstore/mongodb: []uint8 is not assignable to type uuid.UUID docstore/mongo protobuf timestamp panics on get

3 participants