-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
|
||
from typing import TYPE_CHECKING, Annotated | ||
|
||
from fastapi import Depends, status | ||
from fastapi import Depends, HTTPException, status | ||
from sqlalchemy import func, select | ||
from sqlalchemy.orm import Session | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe create a |
||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="start_date parameter is required in the request", | ||
) | ||
|
||
Comment on lines
+53
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
.group_by(DagRun.run_type) | ||
).all() | ||
|
@@ -63,7 +69,7 @@ def historical_metrics( | |
select(DagRun.state, 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()), | ||
) | ||
.group_by(DagRun.state) | ||
).all() | ||
|
@@ -74,7 +80,7 @@ def historical_metrics( | |
.join(TaskInstance.dag_run) | ||
.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()), | ||
) | ||
.group_by(TaskInstance.state) | ||
).all() | ||
|
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