mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-03 08:12:39 +00:00
fix: ensure output directory exists before writing in flow template (#5291)
The `save_content` method wrote to `output/post.md` without ensuring the `output/` directory exists, causing a FileNotFoundError when the directory hasn't been created by another step. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from crewai.flow import Flow, listen, start
|
||||
@@ -42,7 +44,9 @@ class ContentFlow(Flow[ContentState]):
|
||||
@listen(generate_content)
|
||||
def save_content(self):
|
||||
print("Saving content")
|
||||
with open("output/post.md", "w") as f:
|
||||
output_dir = Path("output")
|
||||
output_dir.mkdir(exist_ok=True)
|
||||
with open(output_dir / "post.md", "w") as f:
|
||||
f.write(self.state.final_post)
|
||||
print("Post saved to output/post.md")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user