Skip to content

Bad code generation #1318

@syrn0n

Description

@syrn0n

Bug Report: Missing Closing Parenthesis in Generated Multipart Form Data Code

Summary

The openapi-python-client generator produces invalid Python syntax when generating multipart form data handling code, specifically missing closing parentheses in files.append() calls within the to_multipart() method.

Environment

  • openapi-python-client version: 0.25.2
  • Python version: 3.x
  • Operating System: macOS 24.6.0

OpenAPI Specification

Bug Description

When generating code for the AssetMediaCreateDto model, the generator produces malformed Python code in the to_multipart() method. Specifically, line 180 in the generated file is missing a closing parenthesis:

Generated (incorrect) code:

files.append(("livePhotoVideoId", (None, str(self.live_photo_video_id), "text/plain"))

Expected (correct) code:

files.append(("livePhotoVideoId", (None, str(self.live_photo_video_id), "text/plain")))

Error Details

The missing parenthesis causes a cascade of syntax errors:

SyntaxError: Expected 'else', found ':'
SyntaxError: Unparenthesized generator expression cannot be used here
SyntaxError: Expected ',', found ':'
SyntaxError: Expected ')', found newline

Steps to Reproduce

  1. Run: openapi-python-client generate --overwrite --url https://raw.githubusercontent.com/immich-app/immich/refs/heads/main/open-api/immich-openapi-specs.json
  2. Check the generated file: immich_client/models/asset_media_create_dto.py
  3. Look at line 180 in the to_multipart() method

Expected Behavior

The generator should produce valid Python syntax with properly closed parentheses.

Actual Behavior

The generator produces invalid Python syntax with missing closing parentheses, causing the generated code to fail linting and runtime checks.

Impact

  • Generated code cannot be used without manual fixes
  • Breaks automated CI/CD pipelines that rely on generated code
  • Requires manual intervention after each code generation

Workaround

Currently, the issue must be manually fixed by adding the missing closing parenthesis to the affected line.

Additional Information

This appears to be a template rendering issue in the multipart form data generation logic. The bug is reproducible and occurs consistently in the same location.

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