From fb8deb9749e6345883ed9245c4f7fcb8fdeb878d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puiggen=C3=A9?= Date: Fri, 10 Feb 2023 09:57:54 +0100 Subject: [PATCH] Fix `AttributeError` when running upgrade 240x with stale brains (#2247) * Fix AttributeError when running upgrade 240x * Changelog --- CHANGES.rst | 1 + src/senaite/core/upgrade/v02_04_000.py | 33 ++++++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index c288e4d6b3..9de8d8f5b9 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Changelog 2.4.0 (unreleased) ------------------ +- #2247 Fix `AttributeError` when running upgrade 240x with stale brains - #2246 Update ReactJS to version 18.2.0 - #2245 Add missing translation for "Show more" (from app.listing) - #2243 Add ".pdf" extension to filenames for productivity reports diff --git a/src/senaite/core/upgrade/v02_04_000.py b/src/senaite/core/upgrade/v02_04_000.py index 9782f1f711..926af4bdc7 100644 --- a/src/senaite/core/upgrade/v02_04_000.py +++ b/src/senaite/core/upgrade/v02_04_000.py @@ -169,8 +169,9 @@ def fix_traceback_retract_dl(tool): # reduce memory size of the transaction transaction.savepoint() - obj = api.get_object(brain) - if not obj: + try: + obj = api.get_object(brain) + except AttributeError: uncatalog_brain(brain) continue @@ -405,8 +406,9 @@ def rename_retestof_relationship(tool): transaction.savepoint() # find out if the current analysis is a retest - obj = api.get_object(brain) - if not obj: + try: + obj = api.get_object(brain) + except AttributeError: uncatalog_brain(brain) continue @@ -461,10 +463,12 @@ def purge_backreferences(tool): transaction.savepoint() # Purge back-references to current object - obj = api.get_object(brain) - if not obj: + try: + obj = api.get_object(brain) + except AttributeError: uncatalog_brain(brain) continue + purge_backreferences_to(obj) # Flush the object from memory @@ -582,10 +586,12 @@ def purge_backreferences_analysisrequest(tool): transaction.savepoint() # Purge back-references to current object - obj = api.get_object(brain) - if not obj: + try: + obj = api.get_object(brain) + except AttributeError: uncatalog_brain(brain) continue + purge_backreferences_to(obj) # Flush the object from memory @@ -608,10 +614,12 @@ def migrate_interim_values_to_string(tool): logger.info("Processed objects: {}/{}".format(num, total)) # Migrate float values of interim fields - obj = api.get_object(brain) - if not obj: + try: + obj = api.get_object(brain) + except AttributeError: uncatalog_brain(brain) continue + interims = obj.getInterimFields() for interim in interims: @@ -656,8 +664,9 @@ def ensure_sample_client_fields_are_set(portal): # reduce memory size of the transaction transaction.savepoint() - obj = api.get_object(brain) - if not obj: + try: + obj = api.get_object(brain) + except AttributeError: uncatalog_brain(brain) continue