GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Missing lazy_import in model to_multipart() · Issue #931 · openapi-generators/openapi-python-client

Missing lazy_import in model to_multipart() #931

New issue
Copy link
New issue
Copy link
Closed
Closed
Missing lazy_import in model to_multipart()#931
Copy link

Description

@kgutwin
kgutwin
opened on Jan 3, 2024
Issue body actions

Describe the bug
In the end-to-end tests, the file golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py passes type checking, but would fail in a runtime call in a call to BodyUploadFileTestsUploadPost.to_multipart() at the following point:

    def to_multipart(self) -> Dict[str, Any]:
        some_file = self.some_file.to_tuple()

        some_object = (None, json.dumps(self.some_object.to_dict()).encode(), "application/json")

        some_nullable_object: Union[None, Tuple[None, bytes, str]]
        if isinstance(self.some_nullable_object, BodyUploadFileTestsUploadPostSomeNullableObject):  # raises NameError
            some_nullable_object = (None, json.dumps(self.some_nullable_object.to_dict()).encode(), "application/json")
        else:
            some_nullable_object = self.some_nullable_object

The exception raised is NameError: name 'BodyUploadFileTestsUploadPostSomeNullableObject' is not defined.

The analogous point in to_dict() is avoided because the required model is imported:

    def to_dict(self) -> Dict[str, Any]:
        from ..models.body_upload_file_tests_upload_post_some_nullable_object import (
            BodyUploadFileTestsUploadPostSomeNullableObject,
        )

        some_file = self.some_file.to_tuple()

        some_object = self.some_object.to_dict()

        some_nullable_object: Union[Dict[str, Any], None]
        if isinstance(self.some_nullable_object, BodyUploadFileTestsUploadPostSomeNullableObject):
            some_nullable_object = self.some_nullable_object.to_dict()
        else:
            some_nullable_object = self.some_nullable_object

It appears that model.py.jinja needs to be updated to include the necessary lazy imports:

    def to_dict(self) -> Dict[str, Any]:
        """Convert to a dict"""
    {% for lazy_import in model.lazy_imports | sort %}
        {{ lazy_import }}
    {% endfor %}
        {{ _to_dict() | indent(8) }}

{% if model.is_multipart_body %}
    def to_multipart(self) -> Dict[str, Any]:
        {{ _to_dict(multipart=True) | indent(8) }}
{% endif %}

Activity

  1. kgutwin commented on Jan 3, 2024

    @kgutwin
    kgutwin
    on Jan 3, 2024
    ContributorAuthor
    More actions

    Looking again, is there a reason why the check for if TYPE_CHECKING: is present at the top of model.py.jinja when importing the model's lazy imports?

  2. github-merge-queue
    added a commit that references this issue on Dec 3, 2025

    Fix bad code generation (#1360)

    f5f3b41
  3. dbanty commented on Dec 3, 2025

    @dbanty
    dbanty
    on Dec 3, 2025
    Collaborator
    More actions

    Fixed by #1360

  4. dbanty
    closed this as completedon Dec 3, 2025
  5. github-merge-queue
    added a commit that references this issue on Dec 3, 2025

    Release 0.28.0 (#1368)

    49fa8fc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.