Kartik
10/23/2025, 4:33 PMMarvin
10/23/2025, 4:33 PMMarvin
10/23/2025, 4:38 PMprefect deploy loads an entrypoint given as a file path, it executes that file in a way that sets __name__ == "__main__", which triggers your if __name__ == "__main__": block and runs the flow.
Why this happens
- prefect deploy must import your entrypoint to build the deployment.
- With a file path entrypoint like flows/amazon_transactions_breakdown_transformation.py:transform_amazon_transactions, Prefect executes the file in a mode where __name__ == "__main__".
- That means your “GOOD: This block will NOT run during deployment” block actually does run, calling transform_amazon_transactions(...) immediately.
How to fix it
You have a few good options. Pick one:
1) Use a module path entrypoint instead of a file path
- Make sure your project is importable (add __init__.py to the flows/ folder and ensure your project root is on PYTHONPATH).
- Change the entrypoint in your prefect.yaml to a module path:
entrypoint: flows.amazon_transactions_breakdown_transformation:transform_amazon_transactions
- Then redeploy:
prefect deploy -n '[Tarinika-Inc(US Store)]: Amazon Transactions Breakdown Transformations'
- This way, Prefect will import the module normally and __name__ will not be "__main__".
2) Remove the main block from the flow module
- Delete the block that calls the flow at the bottom of `amazon_transactions_breakdown_transformation.py`:
if __name__ == "__main__":
transform_amazon_transactions(
database="tarinika-inc",
store_timezone_offset_minutes="330"
)
- If you want a quick local runner, put that into a separate script (e.g., scripts/dev_run_amazon.py) that imports and invokes the flow instead.
3) Ensure nothing runs on import in any imported modules
- Because prefect deploy imports your entrypoint, any side-effects in imported modules will also run. Double-check that post_dbt_transformations/marketplaces/amazon/process_transactions.py doesn’t do any work at import time (e.g., running transforms) and that the flow is only executed when explicitly called.
A couple of additional notes
- Your schedule is set to active: false, so even after deployment it won’t schedule runs until you set it to true or create a schedule via the UI/CLI.
- Make sure a worker is running for local-work-pool to actually pick up scheduled or manual runs.
Docs for reference
- Prefect YAML deployments: prefect.yaml deployments
- Creating deployments: Create deployments
If you switch to the module path entrypoint and still see it running during prefect deploy, please share:
- The updated prefect.yaml entrypoint value
- Whether there’s any top-level code in process_transactions.py or other imports that could be doing work on import
- Your Prefect version (prefect version)