Skip to content

'NoneType' object is not subscriptable when serializing fields that do not belong to the database is None #2833

Open
@dinghao-8

Description

@dinghao-8
class UserConfig(SQLModel, table=True):
    __tablename__ = "user_config"
    id: Optional[int] = Field(default=None, primary_key=True)
    user_id: Optional[int]
    _user_name: str = '' #---> not in database fields

    @property
    def user_name(self):
        return self._user_name

    @user_name.setter
    def user_name(self, user_name):
        self._user_name = user_name


class UserConfigSchema(Schema):
    user_id = fields.Int() 
    user_name = fields.Str(allow_none= True)
    id = fields.Int()

    class Meta:
        model = UserConfig
        unknown = EXCLUDE

user_config_schema.dumps(user_config) # --->issue NoneType .....
what i should to do in that time.
Please confirm whether it needs to be repaired or if there are any solutions other than @post_dump

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions