Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception in mini task scheduler. #24865

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions airflow/models/baseoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,22 +1153,25 @@ def on_kill(self) -> None:
"""

def __deepcopy__(self, memo):
"""
Hack sorting double chained task lists by task_id to avoid hitting
max_depth on deepcopy operations.
"""
# Hack sorting double chained task lists by task_id to avoid hitting
# max_depth on deepcopy operations.
sys.setrecursionlimit(5000) # TODO fix this in a better way

cls = self.__class__
result = cls.__new__(cls)
memo[id(self)] = result

shallow_copy = cls.shallow_copy_attrs + cls._base_operator_shallow_copy_attrs

for k, v in self.__dict__.items():
if k == "_BaseOperator__instantiated":
# Don't set this until the _end_, as it changes behaviour of __setattr__
continue
if k not in shallow_copy:
setattr(result, k, copy.deepcopy(v, memo))
else:
setattr(result, k, copy.copy(v))
result.__instantiated = self.__instantiated
return result

def __getstate__(self):
Expand Down
13 changes: 13 additions & 0 deletions tests/models/test_baseoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import copy
import logging
import uuid
from datetime import date, datetime, timedelta
Expand Down Expand Up @@ -765,3 +766,15 @@ def test_task_level_retry_delay(dag_maker):
task1 = BaseOperator(task_id='test_no_explicit_retry_delay', retry_delay=timedelta(seconds=200))

assert task1.retry_delay == timedelta(seconds=200)


def test_deepcopy():
# Test bug when copying an operator attached to a DAG
with DAG("dag0", start_date=DEFAULT_DATE) as dag:

@dag.task
def task0():
pass

MockOperator(task_id="task1", arg1=task0())
copy.deepcopy(dag)