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-2698 Make Comment fields any-type on all options structs and setters #1454

Merged
merged 18 commits into from
Dec 11, 2023

Conversation

prestonvasquez
Copy link
Collaborator

GODRIVER-2698

Summary

Update all comment fields on option structs to accept an "any" type that is later parsed to be either a document or a string.

Background & Motivation

The Comment field on most options structs is an interface. However, on a few structs, Comment is a string because that type was required in an earlier form of the specification. Update all Comment fields and corresponding SetComment setters to be type any.

Copy link
Contributor

mongodb-drivers-pr-bot bot commented Nov 2, 2023

API Change Report

./mongo/options

incompatible changes

(*AggregateOptions).SetComment: changed from func(string) *AggregateOptions to func(interface{}) *AggregateOptions
(*ChangeStreamOptions).SetComment: changed from func(string) *ChangeStreamOptions to func(interface{}) *ChangeStreamOptions
(*CountOptions).SetComment: changed from func(string) *CountOptions to func(interface{}) *CountOptions
(*FindOneOptions).SetComment: changed from func(string) *FindOneOptions to func(interface{}) *FindOneOptions
(*FindOptions).SetComment: changed from func(string) *FindOptions to func(interface{}) *FindOptions
AggregateOptions.Comment: changed from *string to interface{}
ChangeStreamOptions.Comment: changed from *string to interface{}
CountOptions.Comment: changed from *string to interface{}
FindOneOptions.Comment: changed from *string to interface{}
FindOptions.Comment: changed from *string to interface{}

./x/mongo/driver/operation

incompatible changes

##(*Aggregate).Comment: changed from func(string) *Aggregate to func(./x/bsonx/bsoncore.Value) *Aggregate
##(*Find).Comment: changed from func(string) *Find to func(./x/bsonx/bsoncore.Value) *Find

@prestonvasquez prestonvasquez marked this pull request as ready for review November 2, 2023 23:09
@prestonvasquez prestonvasquez requested a review from a team as a code owner November 2, 2023 23:09
@prestonvasquez prestonvasquez requested review from blink1073 and matthewdale and removed request for a team November 2, 2023 23:09
blink1073
blink1073 previously approved these changes Nov 6, 2023
Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

LGTM!

matthewdale
matthewdale previously approved these changes Nov 14, 2023
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 👍

// Unconditionally send a limit to make sure only one document is returned and the cursor is not kept open
// by the server.
findOpts = append(findOpts, options.Find().SetLimit(-1))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: The explicit indexing is somewhat confusing at first and seems brittle. Is there a reason to do that vs using append?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The append method causes the following linting error:

mongo/collection.go:1667:14: append to slice `findOpts` with non-zero initialized length (makezero)
                findOpts = append(findOpts, &options.FindOptions{
                           ^
mongo/collection.go:1685:13: append to slice `findOpts` with non-zero initialized length (makezero)
        findOpts = append(findOpts, options.Find().SetLimit(-1))

Copy link
Collaborator Author

@prestonvasquez prestonvasquez Nov 15, 2023

Choose a reason for hiding this comment

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

@matthewdale Looking at this more closely, I believe that his solution has a pretty insidious bug. Namely if a user passes options like this to the FindOne function: [op1, nil, op2], you would get a runtime fatal. I've updated the PR with a test for this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice find!

matthewdale
matthewdale previously approved these changes Nov 20, 2023
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.

Suggested documentation correction. Otherwise, looks good! 👍

Comment on lines 47 to 48
// A string that will be included in server logs, profiling logs, and currentOp queries to help trace the operation.
// The default is nil, which means that no comment will be included in the logs.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should update the comments to describe the expected value types. For example, Comment fields that are already interface{} have the following documentation:

A string or document that will be included in server logs, profiling logs, and currentOp queries to help trace the operation. The default is nil, which means that no comment will be included in the logs.

That suggestion applies to all doc comments for the updated Comment fields.

@prestonvasquez
Copy link
Collaborator Author

@blink1073 @matthewdale Could you re-review this PR?

blink1073
blink1073 previously approved these changes Dec 6, 2023
matthewdale
matthewdale previously approved these changes Dec 11, 2023
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! 👍

@prestonvasquez prestonvasquez merged commit a372c8c into mongodb:master Dec 11, 2023
31 of 37 checks passed
@prestonvasquez prestonvasquez deleted the GODRIVER-2698 branch December 11, 2023 23:29
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