Skip to content

fix(file): stop is_parent_folder_exist raising on a missing parent - #18930

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
MarMarLabs:fix/parent-folder-exist-arity
Aug 28, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
MarMarLabs:fix/parent-folder-exist-arity

Conversation

@MarMarLabs

Copy link
Copy Markdown
Contributor

Summary

FileService.is_parent_folder_exist calls the cleanup helper with one argument:

parent_files = cls.model.select().where(cls.model.id == parent_id)
if parent_files.count():
    return True
cls.delete_folder_by_pf_id(parent_id)
return False

but that method takes two:

def delete_folder_by_pf_id(cls, user_id, folder_id):

So on the one path this function exists to handle — a parent folder that was deleted or never existed — it raises TypeError: delete_folder_by_pf_id() missing 1 required positional argument: 'folder_id' and never returns False. POST /api/v1/files with such a parent_id reports "Internal server error" instead of the intended "Parent Folder Doesn't Exist!".

The call has never worked: the callee already took two arguments in the same commit that introduced this call site.

Why drop the cleanup rather than pass an argument

That recursive delete has not executed in any release, so wiring it up now would newly destroy rows as a side effect of an existence check. is_parent_folder_exist also has no tenant in scope, while delete_folder_by_pf_id filters by tenant_id and would need one to be safe. Removing the dead call keeps the function doing exactly what its name and docstring say.

The two tests that touch this monkeypatch it as a one-argument lambda, so the signature is unchanged.

How to test

POST /api/v1/files
{"name": "docs", "parent_id": "<id of a folder that does not exist>"}

Before: HTTP 500, "Internal server error".
After: the documented "Parent Folder Doesn't Exist!" response.

The miss path calls delete_folder_by_pf_id(parent_id) with one argument, but
that method takes (user_id, folder_id). Creating a folder under a parent that
was deleted or never existed therefore raises TypeError instead of returning
False, and the route reports "Internal server error" rather than the intended
"Parent Folder Doesn't Exist!".

The call has never worked: the callee already took two arguments in the commit
that introduced this one. Dropping it rather than supplying an argument is
deliberate -- that recursive delete has not run in any release, so wiring it up
now would newly destroy rows as a side effect of an existence check, and this
function has no tenant to scope such a delete by.
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Aug 28, 2026
@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c1a4bb82-05c6-453b-ad9a-55278397d1d5

📥 Commits

Reviewing files that changed from the base of the PR and between cfcd2d6 and e7b8aba.

📒 Files selected for processing (1)
  • api/db/services/file_service.py

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The parent folder existence check now returns a boolean count result. It no longer deletes the folder when no parent file exists.

Changes

Parent folder existence check

Layer / File(s) Summary
Remove deletion side effect
api/db/services/file_service.py
is_parent_folder_exist returns the boolean result of parent_files.count() and no longer calls delete_folder_by_pf_id(parent_id) when the parent folder is absent.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to e7b8a

The change makes missing-parent folder creation return the intended validation error instead of an internal server error, while leaving valid-parent behavior unchanged. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: wangq8, sarbojitrana, rsnetworkinginc

Poem

A rabbit checks the folder door
No broom sweeps the missing floor
A count says yes or no
The files stay where they grow
Hop, hop, the check is clear

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the file service fix and the missing-parent failure it addresses.
Description check ✅ Passed The description follows the required Summary section and explains the bug, root cause, design decision, and test scenario with sufficient detail.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI

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.

@6ba3i 6ba3i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 28, 2026
@6ba3i 6ba3i added the ci Continue Integration label Aug 28, 2026
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.09%. Comparing base (88e80fc) to head (e7b8aba).
⚠️ Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18930      +/-   ##
==========================================
- Coverage   39.25%   39.09%   -0.17%     
==========================================
  Files          54       54              
  Lines       14911    14911              
  Branches      117      117              
==========================================
- Hits         5854     5829      -25     
- Misses       9045     9056      +11     
- Partials       12       26      +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit d132352 into infiniflow:main Aug 28, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants