From 17d467b62d4d3316a589596353313180305fb54c Mon Sep 17 00:00:00 2001 From: matteo porta Date: Wed, 12 Oct 2022 14:52:34 +0200 Subject: [PATCH] db fix --- src/components/archive_synchronizer.py | 2 +- src/test/tdb.py | 29 +++++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/components/archive_synchronizer.py b/src/components/archive_synchronizer.py index d56512e..1b34baf 100644 --- a/src/components/archive_synchronizer.py +++ b/src/components/archive_synchronizer.py @@ -37,7 +37,7 @@ class ArchiveSynchronizer(Component): @db.connection_context() def _get(self): - for record in Archive.select().where((Archive.archived != True) | (Archive.uploaded != True)): # using "is not True" breaks the query. + for record in list(Archive.select().where((Archive.archived != True) | (Archive.uploaded != True))): # using "is not True" breaks the query.. # list() forces the complete execution of the query unlocking the db unlike __enter__() if not self.simulate: if record.archived is not True: record.archived = self.remote_archive(record) is True diff --git a/src/test/tdb.py b/src/test/tdb.py index 5e4b773..4387a76 100644 --- a/src/test/tdb.py +++ b/src/test/tdb.py @@ -59,11 +59,17 @@ class Threaded(QObject): @db.connection_context() # @db.atomic() def start(self): + # for data in Data.select(): while True: - data = Data() - data.save() - print(str(int(QThread.currentThreadId())), data.id, flush=True) - # QThread.msleep(2000) + for data in list(Data.select().order_by(Data.id.desc()))[:1] + [Data()]: + data.save() + print(str(int(QThread.currentThreadId())), data.id, flush=True) + # QThread.msleep(2000) + for i in range(2): + data = Data() + data.save() + print(str(int(QThread.currentThreadId())), data.id, flush=True) + # QThread.msleep(2000) components = {1: Threaded()} @@ -81,7 +87,14 @@ for component_name, thread in threads.items(): # QThread.msleep(1000) QApplication.processEvents() while True: - data = Data() - data.save() - print("main", data.id, flush=True) - # QThread.msleep(2000) + for data in list(Data.select().order_by(Data.id.desc()))[:1] + [Data()]: + data.save() + # print(str(int(QThread.currentThreadId())), data.id, flush=True) + print("main", data.id, flush=True) + # QThread.msleep(2000) + for i in range(2): + data = Data() + data.save() + # print(str(int(QThread.currentThreadId())), data.id, flush=True) + print("main", data.id, flush=True) + # QThread.msleep(2000)