Skip to content

[BUG] [Python] Configuration template unconditionally dependency on urllib3 when httpx is specified #22436

@saschakr

Description

@saschakr

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I saw the bugfix from issue #22415 but there are still the dependency on urllib3 on the template which are generated always.
while there are no more imports on urllib3 there is still the (unnecessary) dependency

Generated Code by version 1.18.0-SNAPSHOT:

pyproject.toml

dependencies = [
  "urllib3 (>=2.1.0,<3.0.0)",
  "python-dateutil (>=2.8.2)",

requirements.txt

urllib3 >= 2.1.0, < 3.0.0

setup.py

REQUIRES = [
    "urllib3 >= 2.1.0, < 3.0.0",
openapi-generator version

latest master (7.18.0-SNAPSHOT)

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs

related issue: #22415
related merge request: #22418

Suggest a fix

Depending on the related mr there should be surrounding {{^async}} blocks on the imports of the urllib3
like that patch

diff --git a/modules/openapi-generator/src/main/resources/python/pyproject.mustache b/modules/openapi-generator/src/main/resources/python/pyproject.mustache
index 6cd7936be55..7eed997a3f4 100644
--- a/modules/openapi-generator/src/main/resources/python/pyproject.mustache
+++ b/modules/openapi-generator/src/main/resources/python/pyproject.mustache
@@ -33,7 +33,9 @@ include = ["{{packageName}}/py.typed"]
 
 [tool.poetry.dependencies]
 python = "^3.9"
+{{^async}}
 urllib3 = ">= 2.1.0, < 3.0.0"
+{{/async}}
 python-dateutil = ">= 2.8.2"
 {{#asyncio}}
 aiohttp = ">= 3.8.4"
@@ -59,7 +61,9 @@ lazy-imports = ">= 1, < 2"
 requires-python = ">=3.9"
 
 dependencies = [
+{{^async}}
   "urllib3 (>=2.1.0,<3.0.0)",
+{{/async}}
   "python-dateutil (>=2.8.2)",
 {{#httpx}}
   "httpx (>=0.28.1)",
diff --git a/modules/openapi-generator/src/main/resources/python/requirements.mustache b/modules/openapi-generator/src/main/resources/python/requirements.mustache
index ee103eba2d7..aef16e4cb7a 100644
--- a/modules/openapi-generator/src/main/resources/python/requirements.mustache
+++ b/modules/openapi-generator/src/main/resources/python/requirements.mustache
@@ -1,4 +1,6 @@
+{{^async}}
 urllib3 >= 2.1.0, < 3.0.0
+{{/async}}
 python_dateutil >= 2.8.2
 {{#asyncio}}
 aiohttp >= 3.8.4
diff --git a/modules/openapi-generator/src/main/resources/python/setup.mustache b/modules/openapi-generator/src/main/resources/python/setup.mustache
index b4589687b17..d65485b42f9 100644
--- a/modules/openapi-generator/src/main/resources/python/setup.mustache
+++ b/modules/openapi-generator/src/main/resources/python/setup.mustache
@@ -15,7 +15,9 @@ NAME = "{{{projectName}}}"
 VERSION = "{{packageVersion}}"
 PYTHON_REQUIRES = ">= 3.9"
 REQUIRES = [
+{{^async}}
     "urllib3 >= 2.1.0, < 3.0.0",
+{{/async}}
     "python-dateutil >= 2.8.2",
 {{#asyncio}}
     "aiohttp >= 3.8.4",

I tested this patch on my project and there are no more dependencies on urllib3, but tbh I cannot say if there are some hidden issues with that patch.

Please let me know if you need any more information.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions