Thursday, 13 October 2022

Why do I get attribution error in fast-api? AttributeError: type object has no attribute

I'm using fast-api and pydantic for modeling in my project, I created a function convert the attributes to dictionary.

from pydantic import BaseModel


class WidgetItem(BaseModel):
    """Class for WidgetItem"""
    adId: str = ''

    @classmethod
    def generate_widget_item_dict(cls):
        return {
            'adId': cls.adId
        }

Im trying to call generate_widget_item_dict() but I got this error:

AttributeError: type object 'WidgetItem' has no attribute 'adId'



from Why do I get attribution error in fast-api? AttributeError: type object has no attribute

No comments:

Post a Comment