From 4ca6c043ac9a88d4f1abbbc69e3b7a9ff9f7685f Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 8 Sep 2021 17:58:48 +0200 Subject: [PATCH] core (memory/sqla): fix `fileUpdate` --- sat/memory/sqla.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sat/memory/sqla.py b/sat/memory/sqla.py index e390a20e..a4e49990 100644 --- a/sat/memory/sqla.py +++ b/sat/memory/sqla.py @@ -19,6 +19,7 @@ import sys import time import asyncio +import copy from datetime import datetime from asyncio.subprocess import PIPE from pathlib import Path @@ -981,14 +982,15 @@ class Storage: )).scalar_one() except NoResultFound: raise exceptions.NotFound + old_value = copy.deepcopy(value) update_cb(value) - stmt = update(orm_col).filter_by(id=file_id) - if not value: + stmt = update(File).filter_by(id=file_id).values({column: value}) + if not old_value: # because JsonDefaultDict convert NULL to an empty dict, we have to - # test both for empty dict and None when we have and empty dict - stmt = stmt.where((orm_col == None) | (orm_col == value)) + # test both for empty dict and None when we have an empty dict + stmt = stmt.where((orm_col == None) | (orm_col == old_value)) else: - stmt = stmt.where(orm_col == value) + stmt = stmt.where(orm_col == old_value) result = await session.execute(stmt) await session.commit()