-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AIP-84 Fix: Allow Null Values for end_date Field in Dashboard Endpint in FastAPI #44043
base: main
Are you sure you want to change the base?
AIP-84 Fix: Allow Null Values for end_date Field in Dashboard Endpint in FastAPI #44043
Conversation
…ries/endpoints and simplify unittests
# DagRuns | ||
dag_run_types = session.execute( | ||
select(DagRun.run_type, func.count(DagRun.run_id)) | ||
.where( | ||
DagRun.start_date >= start_date, | ||
func.coalesce(DagRun.end_date, timezone.utcnow()) <= end_date, | ||
func.coalesce(DagRun.end_date, timezone.utcnow()) <= func.coalesce(end_date, timezone.utcnow()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timezone.utcnow()
can be just defined once at the top of the function to avoid different values due to multiple calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a few suggestions
@@ -365,14 +365,16 @@ def depends(self, tag_name_pattern: str | None = None) -> _DagTagNamePatternSear | |||
return self.set_value(tag_name_pattern) | |||
|
|||
|
|||
def _safe_parse_datetime(date_to_check: str) -> datetime: | |||
def _safe_parse_datetime(date_to_check: str) -> datetime | None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argument type need to be adjusted
@@ -49,12 +49,18 @@ def historical_metrics( | |||
session: Annotated[Session, Depends(get_session)], | |||
) -> HistoricalMetricDataResponse: | |||
"""Return cluster activity historical metrics.""" | |||
if start_date is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DateTimeQuery
need to be adjusted, because by definition, it cannot return str | None
, only str
:
DateTimeQuery = Annotated[str, AfterValidator(_safe_parse_datetime)]
Maybe create a OptionalDateTimeQuery = Annotated[str | None, AfterValidator(_safe_parse_datetime)]
, or maybe DateTimeQuery | None
already works
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="start_date parameter is required in the request", | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be handled automatically by FastAPI. If the Query parameter is properly defined, we shouldn't allow None
. No need to handle that manually here. (Also that would be a 422 and not a 400, because this is how fastapi handles validation errors)
The following were added in #43934 . The changes broke dashboard endpoint probably due
|
related: #43846
safe_date_time
to returnNone
if the input isNone
None
in queries/endpointsI have created a separate PR because write permissions don't allow me to push to the existing PR.
cc: @bbovenzi @pierrejeambrun @tirkarthi
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rst
or{issue_number}.significant.rst
, in newsfragments.