Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/build/lib/airflow/models/dagpickle.py: 72%

18 statements  

« prev     ^ index     » next       coverage.py v7.0.1, created at 2022-12-25 06:11 +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 

19 

20import dill 

21from sqlalchemy import BigInteger, Column, Integer, PickleType 

22 

23from airflow.models.base import Base 

24from airflow.utils import timezone 

25from airflow.utils.sqlalchemy import UtcDateTime 

26 

27 

28class DagPickle(Base): 

29 """ 

30 Dags can originate from different places (user repos, main repo, ...) 

31 and also get executed in different places (different executors). This 

32 object represents a version of a DAG and becomes a source of truth for 

33 a BackfillJob execution. A pickle is a native python serialized object, 

34 and in this case gets stored in the database for the duration of the job. 

35 

36 The executors pick up the DagPickle id and read the dag definition from 

37 the database. 

38 """ 

39 

40 id = Column(Integer, primary_key=True) 

41 pickle = Column(PickleType(pickler=dill)) 

42 created_dttm = Column(UtcDateTime, default=timezone.utcnow) 

43 pickle_hash = Column(BigInteger) 

44 

45 __tablename__ = "dag_pickle" 

46 

47 def __init__(self, dag): 

48 self.dag_id = dag.dag_id 

49 if hasattr(dag, "template_env"): 

50 dag.template_env = None 

51 self.pickle_hash = hash(dag) 

52 self.pickle = dag