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-2766 Support inherited defaultDocumentType #1202

Merged
merged 1 commit into from
Mar 21, 2023

Conversation

prestonvasquez
Copy link
Collaborator

@prestonvasquez prestonvasquez commented Mar 14, 2023

GODRIVER-2766

Summary

The DecodeValue method in the struct codec creates its own DecodeContext to decode the underlying value. This approach can cause issues with ancestor selection, as the defaultDocumentType constraints on empty interfaces are not enforced.

In addition to updating the struct.DecodeValue's DecodeContext, this PR parallelized a subset of the decoder tests.

Background & Motivation

GODRIVER-2407 defined a bug wherein the empty interface codec (EIC) will interpret embedded data to be the same type as the parent (or "ancestor") data. In the case of 2766:

item := &struct {
    A map[primitive.ObjectID]interface{} `json:"foo" bson:"foo"`
}{}
 
jsonData := "{ \"foo\" : {\"63ea2082b1ce23422a8bf9ca\" : { \"bar\" : \"\" } } }"
 
err = json.Unmarshal([]byte(jsonData), item)
if err != nil {
    fmt.Println("json unmarshal err", err.Error())
}

The embedded data is the map {bar: ""} but the EIC is interpreting it as a "map[primitive.ObjectID]interface{}". See PR #951 for the work-around solution and the long-term solution. This PR is necessary because the work-around is currently invalid for the struct codec, a bug uncovered during the investigation of 2766 ticket.

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.

Nice find! Looks good 👍

@prestonvasquez prestonvasquez merged commit 1a78435 into mongodb:master Mar 21, 2023
@prestonvasquez prestonvasquez deleted the GODRIVER-2766 branch March 21, 2023 17:08
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.

2 participants