Closed mvnmgrx closed 2 years ago
Thanks for raising this issue - it would be great if you could raise a pull request :)
I would prefer the more modern approach of f-strings
I've created a PR to fix this issue. Let me know if there is something i missed.
Description
Using the API in combination with the logging module + RotatingFileHandler throws exceptions like
TypeError: not all arguments converted during string formatting
and many others as seen below.Seen on:
Expected Behavior
No exceptions occur when using the API in combination with the logging module configured with a rotating file handler, all module-internal log messages are written to the log file.
Actual Behavior
The stdout is spammed with stack traces complaining abound some string formatting problems as seen in the example down below. The messages that cause these exceptions are not logged to the log file.
Despite this, the API works just fine and returns the requested data from the Inventree server.
How to reproduce
InvenTreeAPI
Or use this minimum working example to reproduce the behavior:
This MWE produces the following log output:
As well as the following console output:
Workaround
The errors in this particular example seem to originate from
inventree/api.py
in line 220:The
debug
method of the logging module is called with the variables to be logged as keyword arguments. The documentation of thedebug
method says:The supplied string in the first argument of the function call does not contain any format placeholders for the formatting operator to merge the arguments into. It seems that this interfers with the logging module in some way when rotating file handlers are used. When changing these lines with the respective string placeholders like below, the MWE from above runs without errors:
Or better, Python f-strings could also be used here:
I would suggest using one of the two styles above when formatting logging messages in the API module, either the first one for backwards compatibility or the last one to comply with Python 3.6 specification. Let me know if this would be a correct fix for this problem and i will happily provide a pull request.