diff --git a/CHANGES b/CHANGES
index d304263..f2229b0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -22,7 +22,8 @@ Pint Changelog
 - Fixed issue where quantities with a very large magnitude would throw an IndexError 
   when using to_compact()
 - Fixed crash when a Unit with prefix is declared for the first time while a Context
-  containing unit redefinitions is active (Issue #1062, Thanks Guido Imperiale)
+  containing unit redefinitions is active
+  (Issues #1062 and #1097, Thanks Guido Imperiale)
 - New implementation of 'Lx' String Format Type Option
   The old implementation treated 'Lx' as 'S' as produced by 'uncertainties'
   package, but that is not fully compatible with SIunitx. The new code protects
@@ -37,6 +38,7 @@ Pint Changelog
 - Fix typo in docs for wraps example with optional arguments. (Issue #1088)
 - Add momentum as a dimension
 
+
 0.11 (2020-02-19)
 -----------------
 
@@ -77,6 +79,7 @@ Pint Changelog
   (Issue #881, Thanks Guido Imperiale)
 - Fixed __array__ signature to match numpy docs (Issue #974, Thanks Ryan May)
 
+
 0.10 (2020-01-05)
 -----------------
 
@@ -354,6 +357,7 @@ Pint Changelog
 - Allow changing shape for Quantities with numpy arrays.
   (Issue #344, thanks tecki)
 
+
 0.7.2 (2016-03-02)
 ------------------
 - Fixed backward incompatibility problem when parsing dimensionless units.
diff --git a/pint/measurement.py b/pint/measurement.py
index dd0f592..826253f 100644
--- a/pint/measurement.py
+++ b/pint/measurement.py
@@ -49,9 +49,7 @@ class Measurement(Quantity):
         if error is MISSING:
             mag = value
         elif error < 0:
-            raise ValueError(
-                "The magnitude of the error cannot be negative".format(value, error)
-            )
+            raise ValueError("The magnitude of the error cannot be negative")
         else:
             mag = ufloat(value, error)
 
diff --git a/pint/registry.py b/pint/registry.py
index 5e1e0fa..84544e1 100644
--- a/pint/registry.py
+++ b/pint/registry.py
@@ -1081,11 +1081,11 @@ class BaseRegistry(metaclass=RegistryMeta):
         """
 
         cache = self._cache.parse_unit
-        if as_delta:
-            try:
-                return cache[input_string]
-            except KeyError:
-                pass
+        # Issue #1097: it is possible, when a unit was defined while a different context
+        # was active, that the unit is in self._cache.parse_unit but not in self._units.
+        # If this is the case, force self._units to be repopulated.
+        if as_delta and input_string in cache and input_string in self._units:
+            return cache[input_string]
 
         if not input_string:
             return self.UnitsContainer()

unit redefinition in a context breaks transform in another context (again)
Reopen of #1062, which I thought I had fixed it in #1064.
I just realised that my PR only moved the problem further: before #1064 the POC was failing at the second iteration; now it fails on the third one.

```python
ureg = pint.UnitRegistry()
for i in range(3):
    print(f"run {i}")
    ctx = pint.Context.from_lines(["@context _", "cal = 4 J"])
    with ureg.context("sp", ctx):
        u = ureg.Unit("nm")
        q = ureg.Quantity(1, u)
        q.to('J')
```
Output:
```
run 0
run 1
run 2
KeyError: 'nanometer'
```
diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py
index 29c7905..6d1e5d1 100644
--- a/pint/testsuite/test_issues.py
+++ b/pint/testsuite/test_issues.py
@@ -693,10 +693,10 @@ class TestIssues(QuantityTestCase):
         assert isinstance(q1, ureg.Quantity)
         assert len(q0) == len(q1) == 0
 
-    def test_issue1062(self):
+    def test_issue1062_issue1097(self):
         # Must not be used by any other tests
         assert "nanometer" not in ureg._units
-        for i in range(2):
+        for i in range(5):
             ctx = Context.from_lines(["@context _", "cal = 4 J"])
             with ureg.context("sp", ctx):
                 q = ureg.Quantity(1, "nm")

pip install -e .[dev]
parse_log_pytest
pytest pytest-cov
apt-get update apt-get install -y gcc
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
coverage==7.8.0
exceptiongroup==1.2.2
iniconfig==2.1.0
packaging==24.2
-e git+https://github.com/hgrecco/pint.git@e350d2174896d903f7c6c548398969850a1cc02f#egg=Pint
pluggy==1.5.0
pytest==8.3.5
pytest-cov==6.0.0
tomli==2.2.1

name: pint
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - coverage==7.8.0
      - exceptiongroup==1.2.2
      - iniconfig==2.1.0
      - packaging==24.2
      - pint==0.12.dev91+ge350d21
      - pluggy==1.5.0
      - pytest==8.3.5
      - pytest-cov==6.0.0
      - tomli==2.2.1
prefix: /opt/conda/envs/pint

pint/testsuite/test_issues.py::TestIssues::test_issue1062_issue1097
pint/testsuite/test_issues.py::TestIssues::test_alternative_angstrom_definition pint/testsuite/test_issues.py::TestIssues::test_angstrom_creation pint/testsuite/test_issues.py::TestIssues::test_issue1032 pint/testsuite/test_issues.py::TestIssues::test_issue104 pint/testsuite/test_issues.py::TestIssues::test_issue105 pint/testsuite/test_issues.py::TestIssues::test_issue170 pint/testsuite/test_issues.py::TestIssues::test_issue252 pint/testsuite/test_issues.py::TestIssues::test_issue29 pint/testsuite/test_issues.py::TestIssues::test_issue323 pint/testsuite/test_issues.py::TestIssues::test_issue339 pint/testsuite/test_issues.py::TestIssues::test_issue354_356_370 pint/testsuite/test_issues.py::TestIssues::test_issue45 pint/testsuite/test_issues.py::TestIssues::test_issue468 pint/testsuite/test_issues.py::TestIssues::test_issue50 pint/testsuite/test_issues.py::TestIssues::test_issue507 pint/testsuite/test_issues.py::TestIssues::test_issue52 pint/testsuite/test_issues.py::TestIssues::test_issue523 pint/testsuite/test_issues.py::TestIssues::test_issue532 pint/testsuite/test_issues.py::TestIssues::test_issue54 pint/testsuite/test_issues.py::TestIssues::test_issue54_related pint/testsuite/test_issues.py::TestIssues::test_issue61 pint/testsuite/test_issues.py::TestIssues::test_issue61_notNP pint/testsuite/test_issues.py::TestIssues::test_issue62 pint/testsuite/test_issues.py::TestIssues::test_issue625a pint/testsuite/test_issues.py::TestIssues::test_issue625b pint/testsuite/test_issues.py::TestIssues::test_issue625c pint/testsuite/test_issues.py::TestIssues::test_issue655a pint/testsuite/test_issues.py::TestIssues::test_issue655b pint/testsuite/test_issues.py::TestIssues::test_issue66 pint/testsuite/test_issues.py::TestIssues::test_issue66b pint/testsuite/test_issues.py::TestIssues::test_issue69 pint/testsuite/test_issues.py::TestIssues::test_issue783 pint/testsuite/test_issues.py::TestIssues::test_issue85 pint/testsuite/test_issues.py::TestIssues::test_issue856 pint/testsuite/test_issues.py::TestIssues::test_issue856b pint/testsuite/test_issues.py::TestIssues::test_issue86 pint/testsuite/test_issues.py::TestIssues::test_issue876 pint/testsuite/test_issues.py::TestIssues::test_issue902 pint/testsuite/test_issues.py::TestIssues::test_issue912 pint/testsuite/test_issues.py::TestIssues::test_issue93 pint/testsuite/test_issues.py::TestIssues::test_issue932 pint/testsuite/test_issues.py::TestIssues::test_issue960 pint/testsuite/test_issues.py::TestIssues::test_issues86b pint/testsuite/test_issues.py::TestIssues::test_micro_creation
CHANGES pint/registry.py pint/measurement.py
CHANGES pint/registry.py pint/measurement.py