From 187418cb40663d486ad937a22a5c670846e0f770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Thu, 22 Apr 2021 09:23:41 +0000 Subject: [PATCH] ENH: automatically split containers to prevent URI too long --- src/caosdb/common/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index c9461b06..efd4a3e7 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -2806,6 +2806,17 @@ class Container(list): this happens, none of them will be deleted. It occurs an error instead. """ + chunk_size = 100 + item_count = len(self) + # Split Container in 'chunk_size'-sized containers (if necessary) to avoid error 414 Request-URI Too Long + if item_count > chunk_size: + for i in range(0, int(item_count/chunk_size)+1): + chunk = Container() + for j in range(i*chunk_size, min(item_count, (i+1)*chunk_size)): + chunk.append(self[j]) + if len(chunk): + chunk.delete() + return self if len(self) == 0: if raise_exception_on_error: -- GitLab