OpenAPITools / OpenAPITools/openapi-generator

[BUG] Python: creating Configuration disables all HTTP debug logging

Open
#10,391 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

This is an offshoot of a bug filed against the Python Kubernetes client (https://github.com/kubernetes-client/python/issues/1530).

Debug mode is disabled automatically in the constructor.
https://github.com/OpenAPITools/openapi-generator/blob/2732c45cc1d0431aa96c91af6476bff9ce36be41/modules/openapi-generator/src/main/resources/python/configuration.mustache#L240

Doing so disables HTTP debug logging for the whole application.
https://github.com/OpenAPITools/openapi-generator/blob/2732c45cc1d0431aa96c91af6476bff9ce36be41/modules/openapi-generator/src/main/resources/python/configuration.mustache#L406-L411

This means that even HTTP requests that have nothing to do with this particular configuration won't be logged anymore. This is neither expected or desirable. Enabling/disabling debug logging should not tamper with the global HTTPConnection.debuglevel setting in any way.

Furthermore, it looks like two separate Configurations will still share their loggers. Consequently, you cannot really have one that has debug disabled and another with debug enabled. Thus it shouldn't be presented as an instance field.

The issues run even deeper. It uses two loggers: "{{packageName}}" and "urllib3". The first can be way too generic and easily conflict with some other library. (For example, the Kubernetes client just ends up with "client".) The latter should not be touched at all, because this package may not be the only thing using urllib3.

I request that the debug property be removed from Configuration entirely. (This would be a breaking change.) Instead, clients should do logging.getLogger('<whatever>').setLevel(logging.DEBUG). If the client wants to enable debug logging for HTTPConnection and/or urllib3, they should do so explicitly themselves. The template should also be fixed to use logging.getLogger(__name__), as is standard practice.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/python/configuration.mustache, especially the constructor near line 240 and logging setup near lines 406-411. Trace how generated Configuration instances affect HTTPConnection.debuglevel and the named loggers. Done means debug configuration is no longer shared globally or exposed as an instance setting, and the generated module uses its own logger without altering urllib3 logging.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.