Skip to content

Commit

Permalink
Add limit 1 if required first value from query result (#33672)
Browse files Browse the repository at this point in the history
(cherry picked from commit e8ba579)
  • Loading branch information
Taragolis authored and ephraimbuddy committed Aug 28, 2023
1 parent 9314b4d commit 8043bab
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions airflow/models/dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def get_previous_dagrun(
]
if state is not None:
filters.append(DagRun.state == state)
return session.scalar(select(DagRun).where(*filters).order_by(DagRun.execution_date.desc()))
return session.scalar(select(DagRun).where(*filters).order_by(DagRun.execution_date.desc()).limit(1))

@provide_session
def get_previous_scheduled_dagrun(self, session: Session = NEW_SESSION) -> DagRun | None:
Expand All @@ -536,6 +536,7 @@ def get_previous_scheduled_dagrun(self, session: Session = NEW_SESSION) -> DagRu
DagRun.run_type != DagRunType.MANUAL,
)
.order_by(DagRun.execution_date.desc())
.limit(1)
)

def _tis_for_dagrun_state(self, *, dag, tis):
Expand Down Expand Up @@ -1380,7 +1381,7 @@ def schedule_tis(
@provide_session
def get_log_template(self, *, session: Session = NEW_SESSION) -> LogTemplate:
if self.log_template_id is None: # DagRun created before LogTemplate introduction.
template = session.scalar(select(LogTemplate).order_by(LogTemplate.id))
template = session.scalar(select(LogTemplate).order_by(LogTemplate.id).limit(1))
else:
template = session.get(LogTemplate, self.log_template_id)
if template is None:
Expand Down

0 comments on commit 8043bab

Please sign in to comment.