mirror of
https://github.com/suitenumerique/docs.git
synced 2026-08-30 11:49:49 +02:00
🐛(backend) stop using add_sibling method to create sandbox document
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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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():
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user