From 1df62429271eec63403bf738784d87c8bf6f03a3 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 19 Mar 2026 08:46:24 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(backend)=20stop=20using=20add=5Fsi?= =?UTF-8?q?bling=20method=20to=20create=20sandbox=20document?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In a past release we added a feature to create a sandbox document to a newly created used. To create this sandbox document, we duplicate an existing document and this duplicate is using the add_sibling method with the "right" agument on this original document. Adding a sibling at the right to a document involve moving right every root document created after the original document, so the path of all this documents are recalculated and changed. This can lead to the lost of some leaf in a tree because to do this operation, multiple locks are created on the database, creating lot of connection to the database and if the max number connection to the database is reached or if the memory allocated by the database is too hight, the database can close all connections leading to inconsistent paths in the Document table. --- CHANGELOG.md | 1 + src/backend/core/models.py | 3 +-- src/backend/core/tests/test_models_users.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c74e880c9..44719c24a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to - ♿️(frontend) fix modal aria-label and name #2014 - ♿️(frontend) fix language dropdown ARIA for screen readers #2020 - ♿️(frontend) fix waffle aria-label spacing for new-window links #2030 +- 🐛(backend) stop using add_sibling method to create sandbox document ## [v4.8.1] - 2026-03-17 diff --git a/src/backend/core/models.py b/src/backend/core/models.py index 0cab0945c..d1869e132 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -285,8 +285,7 @@ class User(AbstractBaseUser, BaseModel, auth_models.PermissionsMixin): ) return - sandbox_document = template_document.add_sibling( - "right", + sandbox_document = Document.add_root( title=template_document.title, content=template_document.content, attachments=template_document.attachments, diff --git a/src/backend/core/tests/test_models_users.py b/src/backend/core/tests/test_models_users.py index cbfa144ed..024d8b0a6 100644 --- a/src/backend/core/tests/test_models_users.py +++ b/src/backend/core/tests/test_models_users.py @@ -216,7 +216,13 @@ def test_models_users_duplicate_onboarding_sandbox_document_creates_sandbox(): When USER_ONBOARDING_SANDBOX_DOCUMENT is set with a valid template document, a new sandbox document should be created for the user with OWNER access. """ + documents_before = factories.DocumentFactory.create_batch(20) template_document = factories.DocumentFactory(title="Getting started with Docs") + documents_after = factories.DocumentFactory.create_batch(20) + + all_documents = documents_before + [template_document] + documents_after + + paths = {document.pk: document.path for document in all_documents} with override_settings(USER_ONBOARDING_SANDBOX_DOCUMENT=str(template_document.id)): user = factories.UserFactory() @@ -233,6 +239,10 @@ def test_models_users_duplicate_onboarding_sandbox_document_creates_sandbox(): access = models.DocumentAccess.objects.get(user=user, document=sandbox_doc) assert access.role == models.RoleChoices.OWNER + for document in all_documents: + document.refresh_from_db() + assert document.path == paths[document.id] + def test_models_users_duplicate_onboarding_sandbox_document_with_invalid_template_id(): """