Skip to content

[SPE-4623] Circular references in models are not handled in Python #1214

Open
@pietrodn

Description

Hi, the generated Python client crashes with OpenAPI models that have circular references.

I'm generating the APIs from the Avalara specification (https://rest.avatax.com/swagger/v2/swagger.json) like this:

SCRIPT_DIR=$(dirname "$0")
curl -o generation/avalara-swagger.json https://rest.avatax.com/swagger/v2/swagger.json
speakeasy openapi transform convert-swagger --schema $SCRIPT_DIR/avalara-swagger.json -o $SCRIPT_DIR/openapi.json
mkdir -p avalara-async-client-source
cp $SCRIPT_DIR/gen.yaml avalara-async-client-source/gen.yaml
speakeasy generate sdk --out avalara-async-client-source --schema $SCRIPT_DIR/openapi.json --lang python

as gen.yaml I am using:

configVersion: 2.0.0
python:
  packageName: avalara-async-client
  version: "0.1.0"
  description: Avalara Async API Client SDK for Python
generation:
  baseServerUrl: https://sandbox-rest.avatax.com

Running the sample from the README crashes badly.

Traceback (most recent call last):
  File "/Users/pd/tmp/avalara/avalara-async-client-source/avalara_sample.py", line 3, in <module>
    import avalara_async_client
  File "/Users/pd/tmp/avalara/avalara-async-client-source/src/avalara_async_client/__init__.py", line 10, in <module>
    from .sdk import *
  File "/Users/pd/tmp/avalara/avalara-async-client-source/src/avalara_async_client/sdk.py", line 3, in <module>
    from .basesdk import BaseSDK
  File "/Users/pd/tmp/avalara/avalara-async-client-source/src/avalara_async_client/basesdk.py", line 3, in <module>
    from .sdkconfiguration import SDKConfiguration
  File "/Users/pd/tmp/avalara/avalara-async-client-source/src/avalara_async_client/sdkconfiguration.py", line 12, in <module>
    from avalara_async_client import models
  File "/Users/pd/tmp/avalara/avalara-async-client-source/src/avalara_async_client/models/__init__.py", line 44, in <module>
    from .activecertificatemodel import (
    ...<2 lines>...
    )
  File "/Users/pd/tmp/avalara/avalara-async-client-source/src/avalara_async_client/models/activecertificatemodel.py", line 4, in <module>
    from .certificatemodel import CertificateModel, CertificateModelTypedDict
  File "/Users/pd/tmp/avalara/avalara-async-client-source/src/avalara_async_client/models/certificatemodel.py", line 14, in <module>
    from .customermodel import CustomerModel, CustomerModelTypedDict
  File "/Users/pd/tmp/avalara/avalara-async-client-source/src/avalara_async_client/models/customermodel.py", line 4, in <module>
    from .activecertificatemodel import (
    ...<2 lines>...
    )
ImportError: cannot import name 'ActiveCertificateModel' from partially initialized module 'avalara_async_client.models.activecertificatemodel' (most likely due to a circular import) (/Users/pd/tmp/avalara/avalara-async-client-source/src/avalara_async_client/models/activecertificatemodel.py)

SPE-4623

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions