Skip to content
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

GODRIVER-2702 Update bsoncore value string to preserve timestamp type #1150

Conversation

prestonvasquez
Copy link
Collaborator

@prestonvasquez prestonvasquez commented Dec 16, 2022

GODRIVER-2702

Summary

Update the "bsoncore.Value#String" method to preserve timestamp int/uint type during string conversion. This method is intended to express BSON as extended JSON and converting the timestamp (I,U) values is in antithesis to specifications.

Background & Motivation

The "CommandStartedMessage" for command logging and monitoring has a field called "command" which is the "relaxed extJSON representation of the command." To accomplish this in the Go Driver, we use the "bsoncore.Value#String" method to convert cmdCopy in the operation executor to a string before logging. However, "bsoncore.Value#String" does not preserve timestamp types and so decoding the resulting string will result in the following error:

var doc bson.Raw
if err := bson.UnmarshalExtJSON([]byte(cmdCopy.String()), true, &doc); err != nil {
        // panic: error: $timestamp t value should be uint32, but instead is string
	panic(fmt.Sprintf("error: %v", err)) 
}

This use-case arises with the addition of the "$$matchAsDocument" and "$$matchAsRoot" operators to the driver test runners, here.

@prestonvasquez prestonvasquez changed the title GODRIVER-2570 update bsoncore value string to preserve timestamp type GODRIVER-2669 update bsoncore value string to preserve timestamp type Dec 16, 2022
@prestonvasquez prestonvasquez changed the title GODRIVER-2669 update bsoncore value string to preserve timestamp type GODRIVER-2702 update bsoncore value string to preserve timestamp type Dec 16, 2022
Copy link
Collaborator

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

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

Looks good 👍

{
"Timestamp.String/Success", Value.String, Value{Type: bsontype.Timestamp, Data: AppendTimestamp(nil, 12345, 67890)},
nil,
[]interface{}{"{\"$timestamp\":{\"t\":12345,\"i\":67890}}"},
Copy link
Contributor

Choose a reason for hiding this comment

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

For clarity, what was the result of this before the change to value.go?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

value_test.go:673: return values at index 0 are not equal. got {"$timestamp":{"t":"12345","i":"67890"}}; want {"$timestamp":{"t":12345,"i":67890}}

@prestonvasquez prestonvasquez merged commit 4e038d8 into mongodb:master Dec 20, 2022
@prestonvasquez prestonvasquez deleted the GODRIVER-2570-update-bsoncore-value-string branch December 20, 2022 16:38
@prestonvasquez prestonvasquez changed the title GODRIVER-2702 update bsoncore value string to preserve timestamp type GODRIVER-2702 Update bsoncore value string to preserve timestamp type May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants