Skip to content

Optional field in model fails validation with error Field required #836

Closed Answered by sebastianzander
sebastianzander asked this question in Questions
Discussion options

You must be logged in to vote

I solved my problem. It seems that I need default = None for that field as well, even though there is already a default given in sa_column = Column(...). My previous impression was, that pydantic only cares about the type annotation, but it doesn't. So my complete working field declaration is:

class Round(RoundBase, table = True):
    # ...
    last_updated: Optional[datetime] = Field(default = None,
                                             sa_column = Column(DateTime(), nullable = True, default = func.now(),
                                                                server_default = text('current_timestamp'),
                                                                onupdate 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tiangolo
Comment options

Answer selected by sebastianzander
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants