Skip to content

fix: keep full filename for BaseFile inputs in normalize_input_files#6177

Open
Hiyaarora wants to merge 1 commit into
crewAIInc:mainfrom
Hiyaarora:fix/normalize-input-files-extension-collision
Open

fix: keep full filename for BaseFile inputs in normalize_input_files#6177
Hiyaarora wants to merge 1 commit into
crewAIInc:mainfrom
Hiyaarora:fix/normalize-input-files-extension-collision

Conversation

@Hiyaarora

Copy link
Copy Markdown

Summary

normalize_input_files builds a {name: file} dict. For most input types the key is the full filename (extension included) — that's what the existing tests assert (e.g. doc1.txt, named.txt). But the BaseFile branch strips the extension before using it as the key, which is both inconsistent with every other branch and causes silent data loss: two BaseFile inputs that share a base name but differ in extension collapse to one entry, and the first is dropped.

Reproduction

from crewai_files import TextFile
from crewai_files.core.sources import FileBytes
from crewai_files.resolution.utils import normalize_input_files

result = normalize_input_files([
    TextFile(source=FileBytes(data=b"json", filename="data.json")),
    TextFile(source=FileBytes(data=b"text", filename="data.txt")),
])
print(list(result.keys()))

Expected: ['data.json', 'data.txt'] (2 entries)
Actual: ['data'] (1 entry — the data.json file is silently dropped)

Fix

Keep the full filename for BaseFile inputs (don't strip the extension), matching the behavior of the file-source branch and the existing tests. Same-base-name files with different extensions no longer collide.

Tests

Added test_normalize_base_file_keeps_full_filename in test_files.py.

Verified locally:

  • uv run pytest lib/crewai/tests/utilities/test_files.py54 passed
  • uv run pytest lib/crewai-files/tests/ (resolution) → passed
  • uv run ruff check / ruff format --check / uv run mypy on the changed files → clean

Disclosure

This PR was prepared with AI assistance (Claude Code), reviewed by me. Please apply the llm-generated label per CONTRIBUTING.

The BaseFile branch stripped the file extension from the dict key, unlike
every other input branch (and the documented behavior in tests, which keep
the full filename). This made naming inconsistent and silently dropped files
when two BaseFile inputs shared a base name but had different extensions
(e.g. data.json and data.txt both collapsed to data).

Keep the full filename so BaseFile matches file-source inputs and same-name
files with different extensions no longer collide. Add a regression test.
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8240444a-6764-47b1-bb37-27035209be77

📥 Commits

Reviewing files that changed from the base of the PR and between e9d568d and 68a2aaf.

📒 Files selected for processing (2)
  • lib/crewai-files/src/crewai_files/resolution/utils.py
  • lib/crewai/tests/utilities/test_files.py
 ________________________________________________
< Press W-A-S-D to move me around your codebase. >
 ------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ 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.

Tip

CodeRabbit can generate a title for your PR based on the changes with custom instructions.

Set the reviews.auto_title_instructions setting to generate a title for your PR based on the changes in the PR with custom instructions.

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