Skip to content

Python dataclass and attrs presets render [object Promise] instead of the class body #2641

Description

@yashs33244

PYTHON_DATACLASS_PRESET and PYTHON_ATTRS_PRESET interpolate renderer.defaultSelf() into a template literal without awaiting it, so the generated class body is the literal string [object Promise].

Reproduce

import { PythonGenerator, PYTHON_DATACLASS_PRESET } from '@asyncapi/modelina';

const generator = new PythonGenerator({ presets: [PYTHON_DATACLASS_PRESET] });
const output = await generator.generate({
  $id: 'User', type: 'object', properties: { name: { type: 'string' } }
});
console.log(output[0].result);

Output:

from dataclasses import dataclass

@dataclass
[object Promise]

Same for PYTHON_ATTRS_PRESET.

defaultSelf() is async, so the self hook just needs to await it (the Pydantic preset already does). I'll open a PR.

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