Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format HTTPError.log_message only if args provided #3465

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hXtreme
Copy link

@hXtreme hXtreme commented Feb 27, 2025

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. When HTTPError.__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

Attempts to fix the [jupyter_server/issues/1503](jupyter-server/jupyter_server#1503) issue
@hXtreme
Copy link
Author

hXtreme commented Feb 27, 2025

It would be great if someone could point me to instruction on how to run tests/lints on the code :)

@bdarnell
Copy link
Member

I'm not sure we have this documented, but the simplest way is to install tox and run something like tox -e lint,docs,py313-full (For simple changes like this you can usually omit docs and -full, and feel free to change py313 to a different version if you have something else installed)

@hXtreme
Copy link
Author

hXtreme commented Feb 28, 2025

@bdarnell I've updated the pr to pass tox -e py312-full

some tests were skipped with the following output:

python -bb -m tornado.test
Ran 1209 tests in 15.091s

OK (skipped=3)
Some tests were skipped because: needs fix, no testable future
imports, py312 has its own check for test case returns
python -O -m tornado.test
Ran 1209 tests in 17.613s

OK (skipped=3)
Some tests were skipped because: needs fix, no testable future
imports, py312 has its own check for test case returns
python -m tornado.test --httpclient=tornado.curl_httpclient.CurlAsyncHTTPClient
Ran 1209 tests in 21.064s

OK (skipped=4)
Some tests were skipped because: curl client accepts invalid headers,
needs fix, no testable future imports, py312 has its own check for
test case returns
python -m tornado.test --resolver=tornado.platform.caresresolver.CaresResolver
Ran 1209 tests in 17.034s

OK (skipped=4)
Some tests were skipped because: localhost does not resolve to ipv4,
needs fix, no testable future imports, py312 has its own check for
test case returns

I couldn't run docs test

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