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

[BUG] [python] Circular imports on inherited discriminators. #16808

Open
5 tasks done
tom300z opened this issue Oct 12, 2023 · 0 comments
Open
5 tasks done

[BUG] [python] Circular imports on inherited discriminators. #16808

tom300z opened this issue Oct 12, 2023 · 0 comments

Comments

@tom300z
Copy link
Contributor

tom300z commented Oct 12, 2023

When generating a python client using the current snapshot of the openapi generator, an circular import occurs when a discriminator is inherited via AllOf.

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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?
    Expected output:
    Running tests via python -m pytest . passes
    Acutal output:
ImportError while importing test module '/home/thoerberg/Documents/Work/repositories/vcd_cloudapi/test/test_group.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
../test/test_group.py:18: in <module>
    from vcd_cloudapi.models.group import Group  # noqa: E501
../vcd_cloudapi/models/group.py:23: in <module>
    from vcd_cloudapi.models.presentation_element import PresentationElement
../vcd_cloudapi/models/presentation_element.py:105: in <module>
    from vcd_cloudapi.models.group import Group
E   ImportError: cannot import name 'Group' from partially initialized module 'vcd_cloudapi.models.group' (most likely due to a circular import) (/home/thoerberg/Documents/Work/repositories/vcd_cloudapi/vcd_cloudapi/models/group.py)
Description

see above

openapi-generator version

the latest Snapshot/freshly built binary

OpenAPI declaration file content or url
{
  "swagger": "2.0",
  "info": {
    "version": "36.3",
    "title": "VMware Cloud Director OpenAPI"
  },
  "basePath": "/cloudapi",
  "tags": [],
  "schemes": [
    "https"
  ],
  "paths": {},
  "definitions": {
    "PresentationElement": {
      "type": "object",
      "required": [
        "elementType"
      ],
      "discriminator": "elementType",
      "properties": {
        "elementType": {
          "type": "string"
        }
      }
    },
    "Group": {
      "allOf": [
        {
          "$ref": "#/definitions/PresentationElement"
        },
        {
          "type": "object",
          "properties": {}
        }
      ]
    }
  }
}
Generation Details
/opt/jdk11/bin/java -jar  /home/thoerberg/Downloads/openapi-generator-cli-7.1.0-20231012.113715-77.jar generate \
  -i input.json \
  -g python \
  -o ...
Suggest a fix

See: PR #16809

fa0311 added a commit to fa0311/openapi-generator that referenced this issue Feb 17, 2024
fa0311 added a commit to fa0311/openapi-generator that referenced this issue Feb 17, 2024
wing328 pushed a commit that referenced this issue Feb 20, 2024
* [python] add inheritance discriminators test #16808

* [python] update samples

* [python] fix assert in test

* [python] fix inheritance discriminators circular import

* [python] update samples

* [python] undo type changes related to discriminator

* [python] remove extraneous processing

* [python-pydantic-v1] fix inheritance discriminators circular import

* [python] remove type ignore comment

* [python] update samples

* [python] fix avoid the empty line break

* [python] update samples
kota65535 pushed a commit to kota65535/openapi-generator that referenced this issue Feb 23, 2024
…ols#17886)

* [python] add inheritance discriminators test OpenAPITools#16808

* [python] update samples

* [python] fix assert in test

* [python] fix inheritance discriminators circular import

* [python] update samples

* [python] undo type changes related to discriminator

* [python] remove extraneous processing

* [python-pydantic-v1] fix inheritance discriminators circular import

* [python] remove type ignore comment

* [python] update samples

* [python] fix avoid the empty line break

* [python] update samples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant