'Returns the last dag run for this dag, None if there was none.
Last dag run can be any type of run eg. scheduled or backfilled.
Overridden DagRuns are ignored'

@provide_session
def get_last_dagrun(self, session=None, include_externally_triggered=False):

    DR = DagRun
    qry = session.query(DR).filter((DR.dag_id == self.dag_id))
    if (not include_externally_triggered):
        qry = qry.filter(DR.external_trigger.__eq__(False))
    qry = qry.order_by(DR.execution_date.desc())
    last = qry.first()
    return last
