stdlib: don't clear LogRecord.args before ProcessorFormatter processors run#810
Open
SarthakB11 wants to merge 1 commit intohynek:mainfrom
Open
stdlib: don't clear LogRecord.args before ProcessorFormatter processors run#810SarthakB11 wants to merge 1 commit intohynek:mainfrom
LogRecord.args before ProcessorFormatter processors run#810SarthakB11 wants to merge 1 commit intohynek:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In the foreign branch of
ProcessorFormatter.format(),record.args = ()was being assigned beforeforeign_pre_chainand the mainprocessorschain ran.Processors that look at
event_dict["_record"].argstherefore always saw an empty tuple, even when stdlib was called with positional args likelogger.info("a=%s b=%s", "a", "b").The clear is necessary: once
record.msgis replaced with the rendered structlog string, leaving non-emptyrecord.argsmakeslogging.Formatter.format()raiseTypeError: not all arguments converted during string formatting.But it only needs to happen after the processor chain.
The fix moves
record.args = ()to right beforerecord.msg = ed/super().format(record)and leaves a comment so a future refactor doesn't drop it again.test_clears_args(the regression guard for the originalTypeError) andtest_pass_foreign_args_true_sets_positional_args_keystill pass.New
test_record_args_accessible_in_processorreproduces #771 at the public API surface and asserts the foreign-pre-chain processor seesrecord.args == ("a", "b").Closes #771.
Pull Request Check List
mainbranch.api.py.docs/api.rstby hand.versionadded,versionchanged, ordeprecateddirectives..rstand.mdfiles is written using semantic newlines.