Repository: apache/airflow

Issue:
Error when querying on the Browse view with empty date picker
**Apache Airflow version**: 2.0.2

**What happened**:

Under Browse, when querying with any empty datetime fields, I received the mushroom cloud.

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.7/site-packages/flask_appbuilder/security/decorators.py", line 109, in wraps
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/flask_appbuilder/views.py", line 551, in list
    widgets = self._list()
  File "/usr/local/lib/python3.7/site-packages/flask_appbuilder/baseviews.py", line 1127, in _list
    page_size=page_size,
  File "/usr/local/lib/python3.7/site-packages/flask_appbuilder/baseviews.py", line 1026, in _get_list_widget
    page_size=page_size,
  File "/usr/local/lib/python3.7/site-packages/flask_appbuilder/models/sqla/interface.py", line 425, in query
    count = self.query_count(query, filters, select_columns)
  File "/usr/local/lib/python3.7/site-packages/flask_appbuilder/models/sqla/interface.py", line 347, in query_count
    query, filters, select_columns=select_columns, aliases_mapping={}
  File "/usr/local/lib/python3.7/site-packages/flask_appbuilder/models/sqla/interface.py", line 332, in _apply_inner_all
    query = self.apply_filters(query, inner_filters)
  File "/usr/local/lib/python3.7/site-packages/flask_appbuilder/models/sqla/interface.py", line 187, in apply_filters
    return filters.apply_all(query)
  File "/usr/local/lib/python3.7/site-packages/flask_appbuilder/models/filters.py", line 298, in apply_all
    query = flt.apply(query, value)
  File "/usr/local/lib/python3.7/site-packages/airflow/www/utils.py", line 373, in apply
    value = timezone.parse(value, timezone=timezone.utc)
  File "/usr/local/lib/python3.7/site-packages/airflow/utils/timezone.py", line 173, in parse
    return pendulum.parse(string, tz=timezone or TIMEZONE, strict=False)  # type: ignore
  File "/usr/local/lib/python3.7/site-packages/pendulum/parser.py", line 29, in parse
    return _parse(text, **options)
  File "/usr/local/lib/python3.7/site-packages/pendulum/parser.py", line 45, in _parse
    parsed = base_parse(text, **options)
  File "/usr/local/lib/python3.7/site-packages/pendulum/parsing/__init__.py", line 74, in parse
    return _normalize(_parse(text, **_options), **_options)
  File "/usr/local/lib/python3.7/site-packages/pendulum/parsing/__init__.py", line 120, in _parse
    return _parse_common(text, **options)
  File "/usr/local/lib/python3.7/site-packages/pendulum/parsing/__init__.py", line 177, in _parse_common
    return date(year, month, day)
ValueError: year 0 is out of range
```

**What you expected to happen**:

Perhaps give a warning/error banner that indicate Airflow cannot perform the search with bad input. I think it'll also work if the datetime picker defaults the timestamp to the current time.

It looks like some fields are equipped to do that but not all.

**How to reproduce it**:
1. Go under Browse
2. Try to query with empty datetime picket

**Anything else we need to know**:
![Screen Shot 2021-05-20 at 5 12 54 PM](https://user-images.githubusercontent.com/5952735/119063940-12b13f80-b98f-11eb-9b6f-a4d5c396e971.png)
![Screen Shot 2021-05-20 at 5 13 36 PM](https://user-images.githubusercontent.com/5952735/119063945-1349d600-b98f-11eb-91cd-92d813414eba.png)
![Screen Shot 2021-05-20 at 5 12 35 PM](https://user-images.githubusercontent.com/5952735/119063948-13e26c80-b98f-11eb-945f-1439a263fc58.png)
![Screen Shot 2021-05-20 at 5 14 17 PM](https://user-images.githubusercontent.com/5952735/119063949-147b0300-b98f-11eb-8e8c-d5ee1e23bfc1.png)
![Screen Shot 2021-05-20 at 5 14 37 PM](https://user-images.githubusercontent.com/5952735/119063950-147b0300-b98f-11eb-9055-c89518bf8524.png)
![Screen Shot 2021-05-20 at 5 15 01 PM](https://user-images.githubusercontent.com/5952735/119063951-147b0300-b98f-11eb-8323-7602bf673205.png)




Discussion:
I wonder what the best solution is. We can ignore empty fields in the backend (and probably should no matter what), but I would want the frontend to block form submission when this happens since leaving a field empty is likely a user error.
These pages and forms are created in Flask so we'd need to disable it there if a field is blank. Probably in `forms.py`?

Resolving patch:
diff --git a/airflow/www/widgets.py b/airflow/www/widgets.py
--- a/airflow/www/widgets.py
+++ b/airflow/www/widgets.py
@@ -42,10 +42,12 @@ def __call__(self, field, **kwargs):
         kwargs.setdefault("id", field.id)
         kwargs.setdefault("name", field.name)
         if not field.data:
-            field.data = ""
+            field.data = ''
         template = self.data_template
 
-        return Markup(template % {"text": html_params(type="text", value=field.data, **kwargs)})
+        return Markup(
+            template % {"text": html_params(type="text", value=field.data, required=True, **kwargs)}
+        )
 
 
 class AirflowDateTimePickerROWidget(AirflowDateTimePickerWidget):


Test patch: