Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/build/lib/airflow/models/dagpickle.py: 71%
21 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
1#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18from __future__ import annotations
20from typing import TYPE_CHECKING
22import dill
23from sqlalchemy import BigInteger, Column, Integer, PickleType
25from airflow.models.base import Base
26from airflow.utils import timezone
27from airflow.utils.sqlalchemy import UtcDateTime
29if TYPE_CHECKING:
30 from airflow.models.dag import DAG
33class DagPickle(Base):
34 """
35 Dags can originate from different places (user repos, main repo, ...)
36 and also get executed in different places (different executors). This
37 object represents a version of a DAG and becomes a source of truth for
38 a BackfillJob execution. A pickle is a native python serialized object,
39 and in this case gets stored in the database for the duration of the job.
41 The executors pick up the DagPickle id and read the dag definition from
42 the database.
43 """
45 id = Column(Integer, primary_key=True)
46 pickle = Column(PickleType(pickler=dill))
47 created_dttm = Column(UtcDateTime, default=timezone.utcnow)
48 pickle_hash = Column(BigInteger)
50 __tablename__ = "dag_pickle"
52 def __init__(self, dag: DAG) -> None:
53 self.dag_id = dag.dag_id
54 if hasattr(dag, "template_env"):
55 dag.template_env = None # type: ignore[attr-defined]
56 self.pickle_hash = hash(dag)
57 self.pickle = dag