Skip to content

What does the update argument to model_validate do, and am I using it correctly? #748

Discussion options

You must be logged in to vote

@MatMoore I just ran into this as well. From digging into things, it looks when you pass a model along with the update param, it creates a ObjectWithUpdateWrapper which is what actually gets validated:

    def sqlmodel_validate(
        cls: Type[_TSQLModel],
        obj: Any,
        *,
        strict: Union[bool, None] = None,
        from_attributes: Union[bool, None] = None,
        context: Union[Dict[str, Any], None] = None,
        update: Union[Dict[str, Any], None] = None,
    ) -> _TSQLModel:
        if not is_table_model_class(cls):
            new_obj: _TSQLModel = cls.__new__(cls)
        else:
            # If table, create the new instance normally to make SQLAlchemy create

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nathan-osman
Comment options

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