From 40cb18f0cc9ac67dc432662a34cf9254cf1cb23e Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 15 Apr 2020 20:53:34 -0500 Subject: [PATCH] Avoid touching DB records when dry-run importing just in case storage engine doesn't support transactions! --- rattail_corepos/corepos/importing/db/model.py | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/rattail_corepos/corepos/importing/db/model.py b/rattail_corepos/corepos/importing/db/model.py index 54d0354..68a0584 100644 --- a/rattail_corepos/corepos/importing/db/model.py +++ b/rattail_corepos/corepos/importing/db/model.py @@ -43,8 +43,39 @@ class ToCore(importing.ToSQLAlchemy): """ Base class for all CORE "operational" model importers. """ - # TODO: should we standardize on the 'id' primary key? (can we even?) - # key = 'id' + + def create_object(self, key, host_data): + + # NOTE! some tables in CORE DB may be using the MyISAM storage engine, + # which means it is *not* transaction-safe and therefore we cannot rely + # on "rollback" if in dry-run mode! in other words we better not touch + # the record at all, for dry run + if self.dry_run: + return host_data + + return super(ToCore, self).create_object(key, host_data) + + def update_object(self, obj, host_data, **kwargs): + + # NOTE! some tables in CORE DB may be using the MyISAM storage engine, + # which means it is *not* transaction-safe and therefore we cannot rely + # on "rollback" if in dry-run mode! in other words we better not touch + # the record at all, for dry run + if self.dry_run: + return obj + + return super(ToCore, self).update_object(obj, host_data, **kwargs) + + def delete_object(self, obj): + + # NOTE! some tables in CORE DB may be using the MyISAM storage engine, + # which means it is *not* transaction-safe and therefore we cannot rely + # on "rollback" if in dry-run mode! in other words we better not touch + # the record at all, for dry run + if self.dry_run: + return True + + return super(ToCore, self).delete_object(obj) class ToCoreTrans(importing.ToSQLAlchemy):