Format HTTPError.log_message only if args provided #3465
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.
Attempts to fix the jupyter_server/issues/1503 issue
For details please see the linked issue. TLDR is that if the
log_message
contents have the literal '%' those are getting converted to '%%' when no formatting args are specified. WhenHTTPError.__str__
is called, log_message is always %-formatted even when no formatting args are specified, and the '%' literal replacement is likely to avoid issues here.This pr performs %-formatting of log_message only when required (args are specified) to avoid having to do the literal replacement.
While not completely a parallel example this is more or less what python's logging module does when creating a string out of a LogRecord:
https://github.com/python/cpython/blob/e06bebb87e1b33f7251196e1ddb566f528c3fc98/Lib/logging/__init__.py#L391-L402
If this is intentionally done for some special reason such as security then maybe this issue could be tackled solely on the jupyter side.
related to: #1393
cc: @ptch314