From 2c25c23be5516934341d4b821239734911517402 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Tue, 10 Sep 2024 07:21:52 -0500 Subject: [PATCH 1/4] Made tests stricter to only insert once. --- tests/test_numbered_collection.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_numbered_collection.py b/tests/test_numbered_collection.py index f88cf831..1a6bd36d 100644 --- a/tests/test_numbered_collection.py +++ b/tests/test_numbered_collection.py @@ -317,11 +317,13 @@ def test_data_append(cp_simple_problem): prob.materials.append(new_mat) assert new_mat in prob.materials assert new_mat in prob.data_inputs + assert prob.data_inputs.count(new_mat) == 1 # trigger getting data_inputs end prob.materials.clear() prob.materials.append(new_mat) assert new_mat in prob.materials assert new_mat in prob.data_inputs + assert prob.data_inputs.count(new_mat) == 1 prob.data_inputs.clear() prob.materials._last_index = None new_mat = copy.deepcopy(next(iter(prob.materials))) @@ -329,6 +331,7 @@ def test_data_append(cp_simple_problem): prob.materials.append(new_mat) assert new_mat in prob.materials assert new_mat in prob.data_inputs + assert prob.data_inputs.count(new_mat) == 1 # trigger getting index of last material prob.materials._last_index = None new_mat = copy.deepcopy(next(iter(prob.materials))) From d14d96daa09b1a4fd09576ce9f485179f16b2165 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Tue, 10 Sep 2024 07:22:15 -0500 Subject: [PATCH 2/4] Replicated error #516. --- tests/test_numbered_collection.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_numbered_collection.py b/tests/test_numbered_collection.py index 1a6bd36d..d5a43f9e 100644 --- a/tests/test_numbered_collection.py +++ b/tests/test_numbered_collection.py @@ -339,6 +339,16 @@ def test_data_append(cp_simple_problem): prob.materials.append(new_mat) assert new_mat in prob.materials assert new_mat in prob.data_inputs + assert prob.data_inputs.count(new_mat) == 1 + + +def test_data_append_renumber(cp_simple_problem): + prob = cp_simple_problem + new_mat = copy.deepcopy(next(iter(prob.materials))) + prob.materials.append_renumber(new_mat) + assert new_mat in prob.materials + assert new_mat in prob.data_inputs + assert prob.data_inputs.count(new_mat) == 1 def test_data_remove(cp_simple_problem): From 8b50e68e69cf5b8499cde1004c832cb287144d64 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Tue, 10 Sep 2024 07:26:15 -0500 Subject: [PATCH 3/4] Changed order of appending to allow failure first. --- montepy/numbered_object_collection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/montepy/numbered_object_collection.py b/montepy/numbered_object_collection.py index e542c82e..bbbd49d3 100644 --- a/montepy/numbered_object_collection.py +++ b/montepy/numbered_object_collection.py @@ -439,6 +439,7 @@ def append(self, obj, insert_in_data=True): :type insert_in_data: bool :raises NumberConflictError: if this object has a number that is already in use. """ + super().append(obj) if self._problem: if self._last_index: index = self._last_index @@ -452,7 +453,6 @@ def append(self, obj, insert_in_data=True): if insert_in_data: self._problem.data_inputs.insert(index + 1, obj) self._last_index = index + 1 - super().append(obj) def __delitem__(self, idx): if not isinstance(idx, int): From d393950b568b80d5feb1cf3a33ea1fa0571b80d9 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Tue, 10 Sep 2024 07:30:27 -0500 Subject: [PATCH 4/4] Updated changelog with #516. --- doc/source/changelog.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst index 530c536c..89e89561 100644 --- a/doc/source/changelog.rst +++ b/doc/source/changelog.rst @@ -4,6 +4,10 @@ MontePy Changelog #Next Version# -------------- +**Bug Fixes** + +* Fixed a bug where ``problem.materials.append_renumber`` would double add a material to ``problem.data_inputs`` (:issue:`516`). + **Performance Improvement** * Fixed method of linking ``Material`` to ``ThermalScattering`` objects, avoiding a very expensive O(N:sup:`2`) (:issue:`510`).