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

AttributeError: 'NoneType' object has no attribute 'fake' #232

Closed
neelz040 opened this issue Jan 17, 2023 · 2 comments
Closed

AttributeError: 'NoneType' object has no attribute 'fake' #232

neelz040 opened this issue Jan 17, 2023 · 2 comments

Comments

@neelz040
Copy link

neelz040 commented Jan 17, 2023

Describe the bug

In my pydantic data model I have the following attribute X: List[Optional[types.Float32]]. When I call fake() of this class I get the error 'AttributeError: 'NoneType' object has no attribute 'fake''

To Reproduce

from dataclasses_avroschema import types
from dataclasses_avroschema.avrodantic import AvroBaseModel 
from typing import List, Optional, Union

class Model(AvroBaseModel):
    A: str
    B: types.Float32
    X: List[Optional[types.Float32]]
    Y: List[Union[types.Float32, None]]

print(Model.fake())

Expected behavior

A='BCGUpoVuoBhZZsPxLBTL' B=3.97300348265236 X=[0.22, 0.3, None] Y=[90.4, 3472.0, None]

@neelz040
Copy link
Author

neelz040 commented Jan 17, 2023

a workaround

from dataclasses_avroschema import types
from dataclasses_avroschema.avrodantic import AvroBaseModel 
from typing import List, Optional, Union, Literal

import random

class Model(AvroBaseModel):
    A: str
    B: types.Float32
    X: List[Optional[types.Float32]]
    # Y: List[Union[types.Float32, None]]

x_data = [round(random.uniform(33.33, 66.66), 2) for _ in range(5)]
x_data.append(None)
print(Model.fake(X=x_data))

Would still appreciate some help with the (initial) above described issue I am facing🙂 Thanks a lot.

@marcosschroh
Copy link
Owner

Thanks for reporting it. I will try to fix it asap

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