fix: strip only the trailing extension in LlamaCloud local file name - #723
fix: strip only the trailing extension in LlamaCloud local file name#723JSap0914 wants to merge 1 commit into
Conversation
get_local_file_name used str.replace(file_ext, "") to drop the extension, which removes every occurrence of the extension substring. For files whose stem also ends with the extension (e.g. report.pdf.pdf) the stem was corrupted (report instead of report.pdf). Use os.path.splitext root instead.
🦋 Changeset detectedLatest commit: e97e0a1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthrough
Changesget_local_file_name Extension Fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Bug
get_local_file_name(inpython/llama-index-server/.../utils/llamacloud.py) builds the local filename for a LlamaCloud-sourced file by stripping the extension like this:str.replaceremoves every occurrence of the extension substring, not just the trailing one. So when a filename's stem also ends with the extension, the stem gets corrupted:report.pdf.pdf→ stem becomesreportinstead ofreport.pdfbackup.tar.tar→ stem becomesbackupinstead ofbackup.tarThis produces the wrong local file name (and therefore the wrong source-node file URL via
get_file_url_from_metadata).Fix
Use the root returned by
os.path.splitext, which strips only the trailing extension:Single-extension filenames are unaffected (
report.pdf→report_<pipeline_id>.pdf).Verification
Added
tests/utils/test_llamacloud.pycovering single-extension, repeated-extension, and metadata-based inputs.Before the fix, the repeated-extension cases failed (e.g.
assert 'report_123.pdf' == 'report_pdf_123.pdf').A changeset is included.
Summary by CodeRabbit
Bug Fixes
report.pdf.pdf), preventing filename corruption.Tests