Skip to content

DRIVERS-3656 test duplicate keys in BSON - #1991

Merged
kevinAlbs merged 5 commits into
mongodb:masterfrom
kevinAlbs:DRIVERS-3656
Oct 6, 2026
Merged

kevinAlbs merged 5 commits into
mongodb:masterfrom
kevinAlbs:DRIVERS-3656

Conversation

@kevinAlbs

Copy link
Copy Markdown
Contributor

Summary

Add prose tests to the BSON corpus for handling duplicate keys.

Details

No behavior changes are expected in BSON libraries. These tests are intended to verify driver documentation that will be required as part of DRIVERS-3656.

Prototype in the C driver: mongodb/mongo-c-driver#2461

Please complete the following before merging:

  • Is the relevant DRIVERS ticket in the PR title?
  • Update changelog.
  • Test changes in at least one language driver.
  • Test these changes against all server versions and topologies (including standalone, replica set, and sharded
    clusters).

@kevinAlbs
kevinAlbs requested a review from NoahStapp October 2, 2026 18:09
@kevinAlbs
kevinAlbs marked this pull request as ready for review October 2, 2026 18:09
@kevinAlbs
kevinAlbs requested a review from a team as a code owner October 2, 2026 18:09
@kevinAlbs
kevinAlbs requested a review from eramongodb October 2, 2026 18:09
Comment thread source/bson-corpus/bson-corpus.md Outdated
builder.append("foo", 1)
builder.append("foo", 2)
got = builder.encode()
# Assert implementation-defined behavior.

@NoahStapp NoahStapp Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This isn't clear on expectation. We should specify that this means, depending on language, one of three results every time:

  1. Last value wins
  2. First value wins
  3. Error

If an implementation has inconsistent behavior, that does violate expectations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I like that idea. Updated as suggested. I added another possible expectation: "Both values preserved in-order". That is libbson's behavior.

Comment thread source/bson-corpus/bson-corpus.md Outdated

```python
elements = list(bson.iter_elements(data))
# Assert implementation-defined behavior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same for these.

Comment thread source/bson-corpus/bson-corpus.md Outdated
# Bytes represent BSON for { 'foo': 1, 'foo': 2 }
data = bytes.fromhex("1700000010666f6f000100000010666f6f000200000000")
got = bson.encode(bson.decode(data))
# Assert implementation-defined behavior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And here and below.

@kevinAlbs
kevinAlbs requested a review from NoahStapp October 2, 2026 18:34

@eramongodb eramongodb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor suggestions; otherwise, LGTM.

Comment thread source/bson-corpus/bson-corpus.md Outdated
Comment thread source/bson-corpus/bson-corpus.md Outdated
Comment thread source/bson-corpus/bson-corpus.md Outdated
Comment thread source/bson-corpus/bson-corpus.md Outdated

@NoahStapp NoahStapp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@kevinAlbs
kevinAlbs merged commit 549238e into mongodb:master Oct 6, 2026
6 checks passed
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