Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 592ebba

Browse files
author
Micheal Gendy
committed
dynamically get pk column
1 parent cea7515 commit 592ebba

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

orm/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ async def bulk_update(
489489
]
490490
expr = (
491491
self.table.update()
492-
.where(self.table.c.id == sqlalchemy.bindparam(self.pkname))
492+
.where(
493+
getattr(self.table.c, self.pkname) == sqlalchemy.bindparam(self.pkname)
494+
)
493495
.values(
494496
{
495497
field: sqlalchemy.bindparam(field)
@@ -498,7 +500,7 @@ async def bulk_update(
498500
}
499501
)
500502
)
501-
pk_list = [{self.pkname: obj.pk} for obj in objs]
503+
pk_list = [{self.pkname: getattr(obj, self.pkname)} for obj in objs]
502504
joined_list = [{**pk, **value} for pk, value in zip(pk_list, new_objs)]
503505
await self.database.execute_many(str(expr), joined_list)
504506

0 commit comments

Comments
 (0)