Skip to content

PYTHON-6237 Fix formatting in $maxKey error messages in json_util - #3186

Open
techi101 wants to merge 4 commits into
mongodb:mainfrom
techi101:fix-maxkey-error-message
Open

techi101 wants to merge 4 commits into
mongodb:mainfrom
techi101:fix-maxkey-error-message

Conversation

@techi101

@techi101 techi101 commented Nov 7, 2026 •

Copy link
Copy Markdown

PYTHON-6237

Changes in this PR

The $maxKey parser in bson/json_util.py passed the doc as a second argument to TypeError instead of formatting it, so the error showed a raw tuple:

('$maxKey value must be 1: %s', ({'$maxKey': 2},))

Its extra-field error also said Bad $minKey. Both now use f-strings, matching the $minKey parser right above it:

$maxKey value must be 1: {'$maxKey': 2}
Bad $maxKey, extra field(s): {'$maxKey': 1, 'x': 1}

I used Claude to help find this, and I reviewed and tested the change myself.

Test Plan

Added test_minkey_maxkey_errors in test/test_json_util.py, which checks both error messages for $minKey and $maxKey. Ran pytest test/test_json_util.py: 28 passed.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

The $maxKey value check passed the doc as a second TypeError argument
instead of formatting it, and the extra-field check said $minKey.
Format both like the $minKey parser does and add a test.

Assisted-by: Claude
@techi101
techi101 requested a review from a team as a code owner November 7, 2026 09:51
@techi101
techi101 requested a review from aclark4life November 7, 2026 09:51
@aclark4life

Copy link
Copy Markdown
Contributor

Thanks @techi101 ! We are tracking this here: https://jira.mongodb.org/browse/PYTHON-6237

@aclark4life aclark4life changed the title Fix $maxKey error messages in json_util PYTHON-6237 Fix $maxKey error messages in json_util Nov 9, 2026
@Jibola Jibola changed the title PYTHON-6237 Fix $maxKey error messages in json_util PYTHON-6237 Fix formatting in $maxKey error messages in json_util Nov 13, 2026

This branch has not been deployed

No deployments
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