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

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

Open
pietrodn opened this issue Jan 15, 2025 · 1 comment
Open

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

pietrodn opened this issue Jan 15, 2025 · 1 comment
Labels

Comments

@pietrodn
Copy link

pietrodn commented Jan 15, 2025

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

@pietrodn pietrodn changed the title Circular imports in models are not handled in Python Circular references in models are not handled in Python Jan 15, 2025
@simplesagar simplesagar changed the title Circular references in models are not handled in Python [SPE-4623] Circular references in models are not handled in Python Jan 15, 2025
@simplesagar
Copy link
Member

Hi @pietrodn thanks for the report. We'll investigate! Could you try going through the onboarding steps shown in your workspace? So instead of generate you would run speakeasy quickstart and run ? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants