change order in save_related -> first upsert self then follow

This commit is contained in:
collerek
2021-03-30 17:33:30 +02:00
parent 347c056c30
commit 04047e4cd9
2 changed files with 4 additions and 4 deletions

View File

@ -191,6 +191,9 @@ class Model(ModelRow):
value = [value] value = [value]
for val in value: for val in value:
if not val.saved or save_all:
await val.upsert()
update_count += 1
if follow: if follow:
update_count = await val.save_related( update_count = await val.save_related(
follow=follow, follow=follow,
@ -198,9 +201,6 @@ class Model(ModelRow):
relation_map=relation_map, relation_map=relation_map,
update_count=update_count, update_count=update_count,
) )
if not val.saved or save_all:
await val.upsert()
update_count += 1
return update_count return update_count
async def update(self: T, **kwargs: Any) -> T: async def update(self: T, **kwargs: Any) -> T:

View File

@ -155,4 +155,4 @@ def create_test_database():
async def test_saving_related_fk_rel(): async def test_saving_related_fk_rel():
async with database: async with database:
async with database.transaction(force_rollback=True): async with database.transaction(force_rollback=True):
await Report.objects.select_all(follow=True).all() await Report.objects.select_all(follow=True).all()