ferruzzi commented on code in PR #44712: URL: https://github.com/apache/airflow/pull/44712#discussion_r1889050943
########## airflow/models/deadline.py: ########## @@ -0,0 +1,90 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from datetime import datetime +from typing import TYPE_CHECKING + +import sqlalchemy_jsonfield +from sqlalchemy import Column, DateTime, Index, Integer, String + +from airflow.models.base import Base, StringID +from airflow.settings import json +from airflow.utils.log.logging_mixin import LoggingMixin +from airflow.utils.session import NEW_SESSION, provide_session + +if TYPE_CHECKING: + from sqlalchemy.orm import Session + + +class Deadline(Base, LoggingMixin): + """A Deadline is a 'need-by' date which triggers a callback if the provided time has passed.""" + + __tablename__ = "deadline" + + id = Column(Integer, primary_key=True, autoincrement=True) + + # If the Deadline Alert is for a DAG, store the DAG ID and Run ID from the dag_run. + dag_id = Column(StringID()) Review Comment: Still working through some test failures and ran into this one which might mean the foreign key isn't going to do what we need. ``` update or delete on table "dag" violates foreign key constraint "deadline_dag_id_fkey" on table "deadline" ``` We don't want to remove the Deadline entry when the dag or dagrun are removed. For example, we decided that the user should still be notified that the dagrun DID finish late, even if it has finished in the meantime. If the fkey is going to enforce that it gets removed or NULLed when the dag or dagrun are removed, that might not work for our needs here. What do you two think? ON DELETE NO ACTION (counterintuitively, to me) means throw the above exception, SET NULL and SET DEFAULT would remove the identifying info that we will need in any messaging about the failed deadline, we explicitly do not want CASCADE, and RESTRICT appears to be the same as NO ACTION in this case. In fact the more I think about this, the more I think we do actually need the dag_run.run_id here and not dag_run.id because if the dagrun table is modified and we can't lookup the user-identifiable info by id, the sequential id is utterly useless to use in any error messages or notifications, but the run_id is still potentially useful to the user. I don't know, what do you guys think is the right play here? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
