Blob Blame History Raw
From cd97f5ebe937b892f0582fc3440d43a38b625b18 Mon Sep 17 00:00:00 2001
From: Tom Kooij <tomkooij@tomkooij.nl>
Date: Sat, 25 May 2019 19:02:45 +0200
Subject: [PATCH] Cast cache to list: cache changes during iteration

Cache items are changed while looping over the cache items, this causes an
`Dictionary keys changed during iteration` error in python>=3.8.

Cast the cache to a list first and iterate over the list to prevent the error.
---
 tables/file.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tables/file.py b/tables/file.py
index ac9d6accc..d924e3626 100644
--- a/tables/file.py
+++ b/tables/file.py
@@ -2849,7 +2849,7 @@ def _update_node_locations(self, oldpath, newpath):
 
         # Update alive and dead descendents.
         for cache in [self._node_manager.cache, self._node_manager.registry]:
-            for nodepath in cache:
+            for nodepath in list(cache):
                 if nodepath.startswith(oldprefix) and nodepath != oldprefix:
                     nodesuffix = nodepath[oldprefix_len:]
                     newnodepath = join_path(newpath, nodesuffix)