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:
Lorenze Jay
2026-04-05 22:21:18 -07:00
committed by GitHub
parent d2e57e375b
commit bce10f5978

View File

@@ -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")