Parameterize whether input is required for AirflowDateTimePickerWidget#31141
Parameterize whether input is required for AirflowDateTimePickerWidget#31141xuganyu96 wants to merge 1 commit intoapache:mainfrom
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
|
airflow/www/widgets.py
Outdated
There was a problem hiding this comment.
@xuganyu96 Thanks for the contribution! :)
I like the idea of making datetime picker optional, but I foresee an issue, I have not gone through the code(@bbovenzi would be able to confirm :) ), but there can be multiple ways you can enforce an input field to be required, adding the required attribute is one of them. So I think adding just this code won't guarantee the behavior for all occurrences. It would be much nicer if we can see in a single PR the change and its usage.
There was a problem hiding this comment.
Thank you for the feedback.
there can be multiple ways you can enforce an input field to be required
Could you please clarify what other ways you are referring to? The only other place I can think of is with wtforms where the forms are validated, but I think these are separate layers of validation that should remain independent.
class PluginWebviewForm(FlaskForm):
required_at_frontend = DateTimeWithTimezoneField(
"Datetime required at frontend",
widget=AirflowDateTimePickerWidget(),
)
required_at_backend = DateTimeWithTimezoneField(
"Datetime required at form validation",
widget=AirflowDateTimePickerWidget(),
validators=[InputRequired()],
)
optional_datetime = DateTimeWithTimezoneField(
"Datetime optional",
widget=AirflowDateTimePickerWidget(input_required=False),
validators=[Optional()],
)What prompted me to make this change is the third field optional_datetime in the form where I want to collect an optional datetime.
I did a quick search and found that AirflowDateTimePicker originally did not contain the "required" attribute at the input tag. Issue #15976 and pull request #18602 changed the widget so that the required attribute is always present, but I think that's too inflexible, and my change aims to make it more flexible.
if we can see in a single PR the change and its usage
Is this comment sufficient, or should I produce documentation, as well?
There was a problem hiding this comment.
You can enforce the required clause by just JS as well but again I'm not entirely sure if there are any scenarios in the airflow codebase where that is the case.
IMO, if you plan to use the optional datetime picker anywhere in the code it would give more context if you make those changes in the same PR.
There was a problem hiding this comment.
Thank you for the feedback.
I am not entirely familiar with using JS to control attributes of an HTML tag. My intended use case is "outside" the Airflow codebase, such as with developing plugins. For relatively simple plugins it would be great to use widgets with Flask/Jinja2 and not have to work with JS, which is why I want to parameterize the required attribute with Python instead of anywhere else.
e257490 to
274778c
Compare
274778c to
79c9b72
Compare
|
Can you rebase to fix the static check issue please ? |
79c9b72 to
5ee765d
Compare
5ee765d to
39e7ead
Compare
I'd like to use Airflow's own datetime picker widget, especially when writing web view plugins with FAB. With the existing implementation, the input is always required, but sometimes I have use cases where a datetime value is optional. This pull request made a simple change that parameterize whether the input tag will have the
requiredattribute when instantiating an instance of this widget.A default
Trueis assigned so that the original behavior is preserved.