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

ModelGenerator's output raises NameError for decimal fields #233

Closed
rgson opened this issue Jan 17, 2023 · 1 comment
Closed

ModelGenerator's output raises NameError for decimal fields #233

rgson opened this issue Jan 17, 2023 · 1 comment

Comments

@rgson
Copy link
Contributor

rgson commented Jan 17, 2023

Describe the bug
Code generated by the ModelGenerator for schemas containing a decimal logical type field cannot run due to a missing import.

To Reproduce

import dataclasses_avroschema

schema = {
    "type": "record",
    "name": "demo",
    "fields": [
        {
            "name": "foo",
            "type": {
                "type": "bytes",
                "logicalType": "decimal",
                "precision": 10,
                "scale": 3
            }
        }
    ]
}
code = dataclasses_avroschema.ModelGenerator().render(schema=schema)

with open("/tmp/generated_code.py", "w") as f:
    print(code, file=f)
python3 /tmp/generated_code.py
Traceback (most recent call last):
  File "/tmp/generated_code.py", line 7, in <module>
    class Demo(AvroModel):
  File "/tmp/generated_code.py", line 8, in Demo
    foo: decimal.Decimal = types.Decimal(scale=3, precision=10)
                           ^^^^^
NameError: name 'types' is not defined. Did you mean: 'type'?

Expected behavior
Loadable code without the NameError.

@marcosschroh
Copy link
Owner

Probably it is missing an import on the top. I will check it

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

No branches or pull requests

2 participants