Hello similar to this answer. I would like to set a Task Instance note.
This is my attempt:
def ti_note():
@task
def set_my_note(**context):
dag_id = context['dag'].dag_id
task_id = context['task'].task_id
execution_date = context['execution_date']
message = f"Note for dag {dag_id}, task {task_id}, and execution date {execution_date}"
session = settings.Session()
task_instance = session.query(DagRun).filter(TaskInstance.dag_id == dag_id,
TaskInstance.task_id == task_id,
TaskInstance.execution_date == execution_date).one()
task_instance.note = message
session.add(task_instance)
session.commit()
session.close()
set_my_note_task = set_my_note()
This is the error I get:
sqlalchemy.exc.MultipleResultsFound: Multiple rows were found when exactly one was required
I understand i need to change .one()
but I don't understand why multiple rows are returned from the query. Thanks