Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG+FIX: Optional field output_file not optional #880

Open
Maralai opened this issue Jul 6, 2024 · 1 comment
Open

BUG+FIX: Optional field output_file not optional #880

Maralai opened this issue Jul 6, 2024 · 1 comment

Comments

@Maralai
Copy link

Maralai commented Jul 6, 2024

The optional field, output_file, does not behave like an optional field, and the field_validator throws an exception because it does not handle the condition when the output_file is None.

The following error occurs:

\crewai\task.py", line 121, in output_file_validattion
    if value.startswith("/"):
AttributeError: 'NoneType' object has no attribute 'startswith'

Example task initialization:

           Task(
                description=self.description,
                expected_output=self.expected_output,
                agent=self.agent_id._build_agent() if self.agent_id else None,
                tools=[tool.build_tool() for tool in self.tool_ids],
                async_execution=self.async_execution,
                callback=self._callback,
                output_pydantic=output_pydantic,
                output_json=output_json,
                output_file=self.output_file if self.output_file else None,
            )

Related Field:

output_file: Optional[str] = Field(
        description="A file path to be used to create a file output.",
        default=None,
    )

Related Method:

    @field_validator("output_file")
    @classmethod
    def output_file_validattion(cls, value: str) -> str:
        """Validate the output file path by removing the / from the beginning of the path."""
        if value.startswith("/"):
            return value[1:]
        return value

Solution:

    @field_validator("output_file")
    @classmethod
    def output_file_validattion(cls, value: str) -> str:
        """Validate the output file path by removing the / from the beginning of the path."""
        if value and value.startswith("/"):
            return value[1:]
        return value
@Maralai Maralai changed the title BUG: Optional field output_file not optional BUG+FIX: Optional field output_file not optional Jul 6, 2024
@Maralai
Copy link
Author

Maralai commented Jul 6, 2024

@joaomdmoura I don't think I will get around to forking the repo and submitting a pull request with the solution stated in this issue at this time. I have, however, rebuilt the distribution and installed it, and the solution resolved the issue.

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

No branches or pull requests

1 participant