MCPcopy Index your code
hub / github.com/fastapi/sqlmodel / sqlmodel_update

Method sqlmodel_update

sqlmodel/main.py:985–1011  ·  view source on GitHub ↗
(
        self: _TSQLModel,
        obj: builtins.dict[str, Any] | BaseModel,
        *,
        update: builtins.dict[str, Any] | None = None,
    )

Source from the content-addressed store, hash-verified

983 return cls.model_validate(obj, update=update)
984
985 def sqlmodel_update(
986 self: _TSQLModel,
987 obj: builtins.dict[str, Any] | BaseModel,
988 *,
989 update: builtins.dict[str, Any] | None = None,
990 ) -> _TSQLModel:
991 use_update = (update or {}).copy()
992 if isinstance(obj, dict):
993 for key, value in {**obj, **use_update}.items():
994 if key in get_model_fields(self):
995 setattr(self, key, value)
996 elif isinstance(obj, BaseModel):
997 for key in get_model_fields(obj):
998 if key in use_update:
999 value = use_update.pop(key)
1000 else:
1001 value = getattr(obj, key)
1002 setattr(self, key, value)
1003 for remaining_key, value in use_update.items():
1004 if remaining_key in get_model_fields(self):
1005 setattr(self, remaining_key, value)
1006 else:
1007 raise ValueError(
1008 "Can't use sqlmodel_update() with something that "
1009 f"is not a dict or SQLModel or Pydantic model: {obj}"
1010 )
1011 return self

Callers 10

update_heroFunction · 0.80
update_heroFunction · 0.80
update_heroFunction · 0.80
update_heroFunction · 0.80
update_heroFunction · 0.80
update_heroFunction · 0.80
update_teamFunction · 0.80
update_heroFunction · 0.80
update_teamFunction · 0.80
test_sqlmodel_updateFunction · 0.80

Calls 1

get_model_fieldsFunction · 0.85

Tested by 1

test_sqlmodel_updateFunction · 0.64