fix support for lazy init for db.update

This commit is contained in:
ducklet 2021-07-27 19:32:47 +02:00
parent 3f9cec3e79
commit b0832b8659

View file

@ -225,6 +225,10 @@ async def get_all(model: Type[ModelType], **kwds) -> Iterable[ModelType]:
async def update(item): async def update(item):
# Support late initializing - used for optimization.
if getattr(item, "_is_lazy", False):
item._lazy_init()
values = asplain(item) values = asplain(item)
keys = ", ".join(f"{k}=:{k}" for k in values if k != "id") keys = ", ".join(f"{k}=:{k}" for k in values if k != "id")
query = f"UPDATE {item._table} SET {keys} WHERE id=:id" query = f"UPDATE {item._table} SET {keys} WHERE id=:id"