stdlib: don't clear LogRecord.args before ProcessorFormatter processors run#810
Closed
SarthakB11 wants to merge 1 commit into
Closed
stdlib: don't clear LogRecord.args before ProcessorFormatter processors run#810SarthakB11 wants to merge 1 commit into
LogRecord.args before ProcessorFormatter processors run#810SarthakB11 wants to merge 1 commit into
Conversation
Owner
|
did you run into the problem yourself too, or did you just try to fix #771? I'm not sure why it should be a problem since we pass args inside of event_dict. Futzing around with stdlib integration is a rather risky endeavor. |
Owner
|
to wit: if I'm not mistaken this patch changes the behavior of |
Author
|
You're right. With this patch, processors calling record.getMessage() during the chain would see the interpolated message instead of the format string, which is a behavior change. The reporter's case is already covered by pass_foreign_args=True (sets event_dict["positional_args"]). Closing. |
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.