Skip to content

🐛(backend) Prevent moving document to its own descendant or self#2208

Open
maboukerfa wants to merge 1 commit intosuitenumerique:mainfrom
maboukerfa:fix/move-file-to-descendent-or-self
Open

🐛(backend) Prevent moving document to its own descendant or self#2208
maboukerfa wants to merge 1 commit intosuitenumerique:mainfrom
maboukerfa:fix/move-file-to-descendent-or-self

Conversation

@maboukerfa
Copy link
Copy Markdown
Contributor

Purpose

When attempting to move a document to itself or to any of its descendants, the server would crash with a 500 Internal Server Error.

Proposal

Handling the exception and returning a 400 Bad Request instead of a 500 Internal Server Error.

Before

Screenshot 2026-04-14 at 06 11 38

After

Screenshot 2026-04-14 at 06 13 04

When attempting to move a document to itself or to any of its
descendants, the server would crash with a 500 Internal Server
Error.

Signed-off-by: Mohamed El Amine BOUKERFA <boukerfa.ma@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2d296a86-8ae9-4bcd-9990-dcd312245b87

📥 Commits

Reviewing files that changed from the base of the PR and between d933435 and 35804f1.

📒 Files selected for processing (2)
  • src/backend/core/api/viewsets.py
  • src/backend/core/tests/documents/test_api_documents_move.py

Walkthrough

The changes add exception handling for document movement operations within a tree hierarchy. The backend API endpoint for moving documents now catches InvalidMoveToDescendant exceptions and returns an HTTP 400 status with a validation error message instead of allowing the exception to propagate. Corresponding test cases are added to validate that moves to descendant nodes and self-moves are properly rejected with the expected error response, while verifying the document hierarchy remains unchanged after failed operations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly summarizes the main change: preventing moving a document to its own descendant or self, which matches the changeset's core purpose.
Description check ✅ Passed The PR description is directly related to the changeset, explaining the problem (500 error when moving to descendant/self) and the solution (return 400 Bad Request instead).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant