-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Saving an empty Buffer throws an error. #755
Comments
EDIT: The actual issue in protobuf-js, while this should also resolve the issue it probably better to fix protobufjs (see below for details) I have update if (value instanceof Buffer) {
// was valueProto.blobValue = buffer;
valueProto.blobValue = value.length == 0 ? '' : value;
return valueProto;
} And it fixes the issue:
Anyway this code looks like it fixes the issue. An other way to fix would be I don't know the code well enough to determine if this is the best possible fix. |
I have done some digging into this bug: Calling function createSerializer(cls: Protobuf.Type): Serialize<object> {
return function serialize(arg: object): Buffer {
const message = cls.fromObject(arg);
return cls.encode(message).finish() as Buffer;
};
} The problems seems to be in The
But the
There should be a When the Buffer is not empty the
Here there is a |
Patching protobufjs/protobuf.js#1500 did resolve the issue. I'll try to move that PR forward and then propagate the fix through the dependencies. |
What work remains to close this issue? |
See protobufjs/protobuf.js#1514 (review), the proper fix in protobuf.js should be in v7 The current nodejs-datastore code uses a workaround that could be removed once protobuf.js is fixed - that v7 is released and nodejs-datastore is updated to use this dep. |
Update v7.0 of protobufjs is staged but not relased. |
https://github.com/protobufjs/protobuf.js/releases shows releases for 7.x+ — checking to see if we've picked these up yet. |
The current minimum version of |
Seems to run ok without workaround. Will create a PR and a test. |
Environment details
@google-cloud/datastore
version: 6.3.0Steps to reproduce
Execute the following code:
It will trigger an error:
Error: 3 INVALID_ARGUMENT: The value "blob" does not contain a value.
I expect to be able to save an empty Buffer without error.
If you change the blob value to
Buffer.from([1, 2, 3])
the error disappears.My use case is that I have a protocol buffer composed of repeated fields only:
It could happen that all repeated fields (including the map) are empty. Because the optional field are not populated, the proto would serialize to an empty
Buffer
.Workaround
The workaround would be to set the value to
null
when the Buffer size is 0.This requires extra code both while saving (to replace the
Buffer
withnull
) and while loading (to replacenull
with the default message).Other
The wording of the message could be improved:
The value "blob" does not contain a value.
, i.e. use field or key instead of the first "value".The text was updated successfully, but these errors were encountered: