From 2088e1f8426d8c77a9bec55c70e223f34a93ff63 Mon Sep 17 00:00:00 2001 From: "Jose P. Faria" Date: Tue, 31 Mar 2026 09:10:23 -0500 Subject: [PATCH] Fix NoneType crash in test_gapfill_database when media is None test_gapfill_database() accesses media.id in the error path (lines 138-156) without checking if media is None. When gapfilling is called with media=None (Complete media) and no solution is found, this crashes with: AttributeError: 'NoneType' object has no attribute 'id' Fix: extract media.id into a local variable with fallback to "Complete" before using it in the gf_sensitivity dict and log message. Co-Authored-By: Claude Opus 4.6 (1M context) --- modelseedpy/core/msgapfill.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modelseedpy/core/msgapfill.py b/modelseedpy/core/msgapfill.py index 0eff4210..77514a73 100755 --- a/modelseedpy/core/msgapfill.py +++ b/modelseedpy/core/msgapfill.py @@ -132,19 +132,20 @@ def test_gapfill_database(self, media, target=None, before_filtering=True,active return True if self.gfpkgmgr.getpkg("GapfillingPkg").test_solution.status == 'infeasible': return False + media_id = media.id if media else "Complete" gf_sensitivity = {} if target != "rxn00062_c0": gf_sensitivity = self.mdlutl.get_attributes("gf_sensitivity", {}) - if media.id not in gf_sensitivity: - gf_sensitivity[media.id] = {} - if target not in gf_sensitivity[media.id]: - gf_sensitivity[media.id][target] = {} + if media_id not in gf_sensitivity: + gf_sensitivity[media_id] = {} + if target not in gf_sensitivity[media_id]: + gf_sensitivity[media_id][target] = {} filter_msg = " " note = "FAF" if before_filtering: filter_msg = " before filtering " note = "FBF" - gf_sensitivity[media.id][target][ + gf_sensitivity[media_id][target][ note ] = self.mdlutl.find_unproducible_biomass_compounds(target) if target != "rxn00062_c0": @@ -153,7 +154,7 @@ def test_gapfill_database(self, media, target=None, before_filtering=True,active "No gapfilling solution found" + filter_msg + "for " - + media.id + + media_id + " activating " + target )