Repository navigation
Conversation
|
Assigned |
|
hey! Thanks for your contribution! I'll take a closer look at it tomorrow (as it's late for me already) but fwiw at a glance it looks about right! |
sleepyStick
left a comment
There was a problem hiding this comment.
could you also resolve the merge conflicts for the changelog?
|
|
||
| with patch.dict("os.environ"): | ||
| os.environ.pop("MONGOB_LOG_MAX_DOCUMENT_LENGTH", None) | ||
| os.environ.pop("MONGODB_LOG_MAX_DOCUMENT_LENGTH", None) |
There was a problem hiding this comment.
should this test also pop the mispelled MONGOB_LOG_MAX_DOCUMENT_LENGTH as well to see the real default?
|
thanks! good call on the default test, i added the pop for the misspelled name in both test files so it actually sees the real default now. also resolved the changelog conflict. since 4.20.1 went out i put the entry under a new 4.21.0 (unreleased) section, lmk if you'd rather it go somewhere else. |
perf tyty!
4.21.0 is the correct section! this is my bad for not noticing that you had pushed fixes earlier but there's another changelog conflict...mind fixing it again? and feel free to re-request my review once that's resolved! |
|
in the interest in getting this in quickly, i've resolved the merge conflicts! |
PYTHON-5939
Changes in this PR
LogMessage._redactinpymongo/logger.pyreads the truncation limit fromMONGOB_LOG_MAX_DOCUMENT_LENGTH(missing the "D"). The logging spec and the PyMongo logging docs both say the variable isMONGODB_LOG_MAX_DOCUMENT_LENGTH, so anyone who follows the docs gets the default 1000 character limit no matter what they set.Repro on 4.20.0 and main:
The
commandfield comes out at 94 characters instead of being cut to 10 plus....The fix reads
MONGODB_LOG_MAX_DOCUMENT_LENGTHfirst and falls back to the misspelled name when it is not set, so nobody who already relies on the old name gets a behavior change. This follows the comment on the ticket about keeping both names for at least one minor release. I did not add a deprecation warning for the old name because the value is read while a log record is being formatted. With warnings turned into errors, that warning would surface as a logging error instead of pointing at user code. Happy to add one somewhere else if you want the old name on a removal path.I also updated the existing tests and
test/helpers_shared.pyto use the correct name, and added a changelog entry.I used Claude to find the ticket and draft the fix and tests; I reviewed every line and can explain the change.
Test Plan
Added
TestLogMessageTruncationtotest/asynchronous/test_logger.py, with the same change intest/test_logger.pymatching the synchro output. It builds aLogMessagedirectly, so it does not need a server, and checks that:MONGODB_LOG_MAX_DOCUMENT_LENGTHsets the limitMONGODB_LOG_MAX_DOCUMENT_LENGTHwins when both names are setMONGOB_LOG_MAX_DOCUMENT_LENGTHstill works on its ownOn main, the first two fail (
94 != 13and23 != 13). With the fix,pytest test/test_logger.py test/asynchronous/test_logger.pygives 6 passed. The 12 integration tests in that module were skipped locally because I did not have a mongod running, so CI will be the first full run of the renamed variable in those tests. ruff and mypy pass on the changed files.Checklist
Checklist for Author
Checklist for Reviewer