From d1677403150bee7ce45bfcc878d2f0a0a9333c10 Mon Sep 17 00:00:00 2001 From: Andrew Pontzen Date: Sun, 16 Jun 2024 14:06:13 +0100 Subject: [PATCH] Fix bug with property_importer when executed in parallel seeing database locks --- tangos/tools/property_importer.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tangos/tools/property_importer.py b/tangos/tools/property_importer.py index 23741ade..0fcbf96d 100644 --- a/tangos/tools/property_importer.py +++ b/tangos/tools/property_importer.py @@ -87,8 +87,13 @@ def _import_properties_for_timestep(self, ts, property_names, object_typetag): self._object_cache = timestep_object_cache.TimestepObjectCache(ts) self._session = core.Session.object_session(ts) - property_db_names = [core.dictionary.get_or_create_dictionary_item(self._session, name) for name in - property_names] + with parallel_tasks.ExclusiveLock("add_properties"): + # if a dictionary item may be created, we need the database locked. But note this may be highly inefficent. + # Leaving it for now since this whole property_importer step isn't a rate limiting factor in any known workflow + property_db_names = [core.dictionary.get_or_create_dictionary_item(self._session, name) for name in + property_names] + self._session.commit() + rows_to_store = [] for values in self.handler.iterate_object_properties_for_timestep(ts.extension, object_typetag, property_names): if len(values)!=2+len(property_db_names):