Uh oh!
There was an error while loading. Please reload this page.
.sqlmodel_update() raise RuntimeError: dictionary changed size during iteration #982
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example Codedeffoo(hero_in:HeroCreate, related_id:int, owner_id:int):
hero.sqlmodel_update(
hero_in,
update={
"related_id": related_id,
"owner_id": owner_id,
},
)
#####defsqlmodel_update(
self: _TSQLModel,
obj: Union[Dict[str, Any], BaseModel],
*,
update: Union[Dict[str, Any], None] =None,
) ->_TSQLModel:
use_update= (updateor {}).copy()
ifisinstance(obj, dict):
forkey, valuein {**obj, **use_update}.items():
ifkeyinget_model_fields(self):
setattr(self, key, value)
elifisinstance(obj, BaseModel):
forkeyinget_model_fields(obj):
ifkeyinuse_update:
value=use_update.pop(key)
else:
value=getattr(obj, key)
setattr(self, key, value)
forremaining_keyinuse_update:
ifremaining_keyinget_model_fields(self):
value=use_update.pop(remaining_key) # NOTE the problem is here.setattr(self, remaining_key, value)
else:
raiseValueError(
"Can't use sqlmodel_update() with something that "f"is not a dict or SQLModel or Pydantic model: {obj}"
)
returnselfDescriptionHi @tiangolo , thanks for sqlmodel. forremaining_keyinuse_update:
ifremaining_keyinget_model_fields(self):
value=use_update.pop(remaining_key) # NOTE the problem is here.setattr(self, remaining_key, value)Instead of Operating SystemmacOS Operating System DetailsMac Os M2 SQLModel Version0.0.16 Python Version3.10.14 Additional ContextNo response |
Answered by
BartSchuurmans
Jul 1, 2024
Replies: 1 comment 1 reply
I've submitted a fix in #997 |
1 reply
Answer selected byYuriiMotov
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
I've submitted a fix in #997