From 2a9d1a60ecab85557c7948d19ddfd43aaff264f5 Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Tue, 13 Jan 2026 10:00:25 -0500 Subject: [PATCH] Fix copying of ConfigChoiceField and RegistryField. --- doc/changes/DM-53791.bugfix.md | 1 + python/lsst/pex/config/configChoiceField.py | 2 +- tests/test_configChoiceField.py | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 doc/changes/DM-53791.bugfix.md diff --git a/doc/changes/DM-53791.bugfix.md b/doc/changes/DM-53791.bugfix.md new file mode 100644 index 00000000..a93233ad --- /dev/null +++ b/doc/changes/DM-53791.bugfix.md @@ -0,0 +1 @@ +Fix copying of `ConfigChoiceField` and `RegistryField`. diff --git a/python/lsst/pex/config/configChoiceField.py b/python/lsst/pex/config/configChoiceField.py index b96f66c9..412c5b63 100644 --- a/python/lsst/pex/config/configChoiceField.py +++ b/python/lsst/pex/config/configChoiceField.py @@ -192,7 +192,7 @@ def _copy(self, config: Config) -> ConfigInstanceDict: result._typemap = self._typemap if self._selection is not None: if self._field.multi: - result._selection = SelectionSet(result._dict, self._selection._set) + result._selection = SelectionSet(self, self._selection._set) else: result._selection = self._selection return result diff --git a/tests/test_configChoiceField.py b/tests/test_configChoiceField.py index f2fbf7cd..71147631 100644 --- a/tests/test_configChoiceField.py +++ b/tests/test_configChoiceField.py @@ -165,6 +165,20 @@ def testNoPickle(self): with self.assertRaises(pexConfig.UnexpectedProxyUsageError): pickle.dumps(self.config.c.names) + def test_copy(self): + """Test the copy method on a ConfigChoiceField.""" + copy1: Config3 = self.config.copy() + copy1.a["AAA"].f = 1 + copy1.a["BBB"].f = 1.0 + copy1.a = "BBB" + self.assertEqual(self.config.a.name, "AAA") + self.assertEqual(self.config.a.active.f, 4) + self.assertEqual(self.config.a["AAA"].f, 4) + self.assertEqual(self.config.a["BBB"].f, 0.5) + self.assertEqual(copy1.a.name, "BBB") + self.assertEqual(copy1.a["AAA"].f, 1) + self.assertEqual(copy1.a["BBB"].f, 1.0) + if __name__ == "__main__": unittest.main()