Skip to content

Commit

Permalink
query for true instead of querying the object
Browse files Browse the repository at this point in the history
  • Loading branch information
aneesh-joseph committed Jul 29, 2020
1 parent ef824bf commit 4eb8032
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion airflow/models/dagcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from datetime import datetime

from sqlalchemy import BigInteger, Column, String, UnicodeText, and_
from sqlalchemy.sql.expression import literal

from airflow.exceptions import AirflowException, DagCodeNotFound
from airflow.models import Base
Expand Down Expand Up @@ -160,7 +161,7 @@ def has_dag(cls, fileloc, session=None):
:param session: ORM Session
"""
fileloc_hash = cls.dag_fileloc_hash(fileloc)
return session.query(cls).filter(cls.fileloc_hash == fileloc_hash)\
return session.query(literal(True)).filter(cls.fileloc_hash == fileloc_hash)\
.first() is not None

@classmethod
Expand Down
5 changes: 3 additions & 2 deletions airflow/models/serialized_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import sqlalchemy_jsonfield
from sqlalchemy import BigInteger, Column, Index, String, and_
from sqlalchemy.sql.expression import literal

from airflow.models.base import ID_LEN, Base
from airflow.models.dag import DAG
Expand Down Expand Up @@ -92,7 +93,7 @@ def write_dag(cls,
# If Yes, does nothing
# If No or the DAG does not exists, updates / writes Serialized DAG to DB
if min_update_interval is not None:
if session.query(cls).filter(
if session.query(literal(True)).filter(
and_(cls.dag_id == dag.dag_id,
(timezone.utcnow() - timedelta(seconds=min_update_interval)) < cls.last_updated)
).first() is not None:
Expand Down Expand Up @@ -177,7 +178,7 @@ def has_dag(cls, dag_id, session=None):
:param session: ORM Session
:rtype: bool
"""
return session.query(cls).filter(cls.dag_id == dag_id).first() is not None
return session.query(literal(True)).filter(cls.dag_id == dag_id).first() is not None

@classmethod
@db.provide_session
Expand Down

0 comments on commit 4eb8032

Please sign in to comment.