-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Format HTTPError.log_message only if args provided #3465
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
Conversation
Attempts to fix the [jupyter_server/issues/1503](jupyter-server/jupyter_server#1503) issue
5ec7c7a to
ec08dd3
Compare
|
It would be great if someone could point me to instruction on how to run tests/lints on the code :) |
|
I'm not sure we have this documented, but the simplest way is to install tox and run something like |
60da6af to
ff9ae15
Compare
|
@bdarnell I've updated the pr to pass some tests were skipped with the following output: I couldn't run docs test |
|
The pr should be ready to review, please let me know if you have any feedback or would like me to make additional changes! Thank you :) |
|
This looks good and is probably the way we should have done it from the beginning. My only hesitation is that it's a little backwards-incompatible. If someone were using What is jupyter doing with these exceptions that's showing unprocessed |
I'll defer this to @ptch314, I am too new a contributor to jupyter to be able to answer this fully; I'll also ask someone that's a lot more involved with jupyter to answer this. Here's the gist of what I understand, a user of jupyter server wants to return a url encoded url in certain error cases, they noticed that the '%' chars in the encoded url gets converted to '%%' which causes the string that's returned to not be a valid url-encoded url. (wow that was a lot of 'url's) In more lower-level detail, jupyter uses f-strings to construct the log message that's passed into For backwards compatibility concerns, if I'm understanding this correctly if downstream someone is overriding |
|
Let me know if this approach of using a
I'm currently away from any machine where I can test my most recent changes but will be able to test them by Monday 17th. |
Thanks @hXtreme, I think you have given a good summary of our jupyter use case. For clarification, we are simply an outside user of jupyter. The issue we ran into is that jupyter does not properly pass error messages we create that include % symbols. I think we as well as jupyter expect error message strings (that may contain %s) to be passed through as-is, but the code in tornado over-processes the log_message and replaces |
Here's my understanding of it: Jupyter defines a base class for REST API handlers. That base class overrides the The When the JupyterLab UI receives the HTTP response from one of these API handlers with an error status code, it displays the Additional background: The place we first hit this was here. That's invoked from here, which is a handler that receives requests from the JupyterLab UI running in a browser. The base class of that handler is the APIHandler referenced above. |
This looks reasonable to me, but it means we also need to change Jupyter in order to fix the original bug. The APIHandler in Jupyter uses the I assume that is what you were thinking, but I wanted to make sure we're all on the same page. |
Yes, exactly. (I'm not sure if anyone is actually doing this - it's possible that anyone using
Jupyter is using
Yes, and this is unfortunate. The change looks good and is fully backwards-compatible, but if it still requires changes in jupyter to use the new interfaces, is it worth the complexity? The alternative would be a fix solely on jupyter's side to do what |
|
With the approval of PEP 750 Template Strings, I think a change to HTTPError is warranted, to encapsulate the message formatting and allow template strings to eventually replace the use of a printf-style string and I'm not ready to make any final changes here since template strings aren't available yet, but I think this is a good start. |
Attempts to fix the jupyter_server/issues/1503 issue
For details please see the linked issue. TLDR is that if the
log_messagecontents 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