Skip to content

Commit

Permalink
Fixed output_file not respecting system path (#1726)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Hancock (bhancock_ai) <109994880+bhancockio@users.noreply.github.com>
  • Loading branch information
frieda-huang and bhancockio authored Dec 9, 2024
1 parent 11a3d4b commit bc2a86d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/crewai/task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
import json
import os
from pathlib import Path
import threading
import uuid
from concurrent.futures import Future
Expand Down Expand Up @@ -393,12 +393,13 @@ def _save_file(self, result: Any) -> None:
if self.output_file is None:
raise ValueError("output_file is not set.")

directory = os.path.dirname(self.output_file) # type: ignore # Value of type variable "AnyOrLiteralStr" of "dirname" cannot be "str | None"
resolved_path = Path(self.output_file).expanduser().resolve()
directory = resolved_path.parent

if directory and not os.path.exists(directory):
os.makedirs(directory)
if not directory.exists():
directory.mkdir(parents=True, exist_ok=True)

with open(self.output_file, "w", encoding="utf-8") as file:
with resolved_path.open("w", encoding="utf-8") as file:
if isinstance(result, dict):
import json

Expand Down

0 comments on commit bc2a86d

Please sign in to comment.