What is best practice pattern for using a string Param with format="date"
?
#39461
Unanswered
will-byrne-cardano
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I have two issues with using the date format on a string Param and I was looking for some guidance on what the best pattern/approach is.
Issues
None
/null
as a default. Normally this occurs in situations where I have a run_date that a user can trigger a dag for and if there is no date supplied, the project code will "find" the date to run for by some calculation e.g. looking at the last modified date in a db table or working out based on some business day logic.Solutions
1. Use Dummy default date
In order to solve 1 I have in the past resorted to using a dummy date e.g.
1900-01-01
that is used as a proxy for an empty date. Then have an task in my dag that verifies the date is not equal to the default. If it is then it raises an error. Something like below:The problem I have with this is that it feels really heavy-handed and I feel there should be something native built in to handle this optional date scenario. Am I missing some trick that I've not been able to find in the docs here? If I have to do this in lots of Dags it becomes quite repetitive.
2. Force param selection
We have some legacy dags that don't all make use of Params and are in the course of migrating these to use Params. Because of that, we use the config option (as an environment variable)
AIRFLOW__WEBSERVER__SHOW_TRIGGER_FORM_IF_NO_PARAMS
. When this is used with the default date pattern above, we end up in a scenario where users run a dag that is intended to have a user input, without user input. The dag fails, so they (or, more often, me) have to run it again with the correct parameters. My question is: Once we've migrated all legacy dags to use params and removed this configuration, will users be forced to enter parameters when triggering in the UI?Beta Was this translation helpful? Give feedback.
All reactions