Skip to content

Commit

Permalink
[AIRFLOW-7079] Remove redundant code for storing template_fields (#7750)
Browse files Browse the repository at this point in the history
cherry-picked from de7e934
  • Loading branch information
kaxil committed Mar 24, 2020
1 parent 5558474 commit 5209665
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 33 deletions.
12 changes: 1 addition & 11 deletions airflow/contrib/operators/bigquery_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

import json
from typing import Iterable, FrozenSet, Optional
from typing import Iterable

from airflow.contrib.hooks.bigquery_hook import BigQueryHook
from airflow.contrib.hooks.gcs_hook import GoogleCloudStorageHook, _parse_gcs_url
Expand Down Expand Up @@ -168,9 +168,6 @@ class BigQueryOperator(BaseOperator):
template_ext = ('.sql', )
ui_color = '#e4f0e8'

# The _serialized_fields are lazily loaded when get_serialized_fields() method is called
__serialized_fields = None # type: Optional[FrozenSet[str]]

@property
def operator_extra_links(self):
"""
Expand Down Expand Up @@ -314,13 +311,6 @@ def on_kill(self):
self.log.info('Cancelling running query')
self.bq_cursor.cancel_query()

@classmethod
def get_serialized_fields(cls):
"""Serialized BigQueryOperator contain exactly these fields."""
if not cls.__serialized_fields:
cls.__serialized_fields = frozenset(BaseOperator.get_serialized_fields() | {"sql"})
return cls.__serialized_fields


class BigQueryCreateEmptyTableOperator(BaseOperator):
"""
Expand Down
12 changes: 1 addition & 11 deletions airflow/contrib/operators/qubole_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""Qubole operator"""

import re
from typing import FrozenSet, Iterable, Optional
from typing import Iterable

from airflow.contrib.hooks.qubole_hook import (
COMMAND_ARGS, HYPHEN_ARGS, POSITIONAL_ARGS, QuboleHook, flatten_list,
Expand Down Expand Up @@ -183,9 +183,6 @@ class QuboleOperator(BaseOperator):
QDSLink(),
)

# The _serialized_fields are lazily loaded when get_serialized_fields() method is called
__serialized_fields = None # type: Optional[FrozenSet[str]]

@apply_defaults
def __init__(self, qubole_conn_id="qubole_default", *args, **kwargs):
self.args = args
Expand Down Expand Up @@ -245,10 +242,3 @@ def __setattr__(self, name, value):
self.kwargs[name] = value
else:
object.__setattr__(self, name, value)

@classmethod
def get_serialized_fields(cls):
"""Serialized QuboleOperator contain exactly these fields."""
if not cls.__serialized_fields:
cls.__serialized_fields = frozenset(BaseOperator.get_serialized_fields() | {"qubole_conn_id"})
return cls.__serialized_fields
11 changes: 1 addition & 10 deletions airflow/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import re
import unittest
from typing import FrozenSet, Optional

import attr

Expand Down Expand Up @@ -108,8 +107,7 @@ def get_link(self, operator, dttm):

class CustomOperator(BaseOperator):

# The _serialized_fields are lazily loaded when get_serialized_fields() method is called
__serialized_fields = None # type: Optional[FrozenSet[str]]
template_fields = ['bash_command']

@property
def operator_extra_links(self):
Expand All @@ -133,13 +131,6 @@ def execute(self, context):
self.log.info("Hello World!")
context['task_instance'].xcom_push(key='search_query', value="dummy_value")

@classmethod
def get_serialized_fields(cls):
"""Stringified CustomOperator contain exactly these fields."""
if not cls.__serialized_fields:
cls.__serialized_fields = frozenset(BaseOperator.get_serialized_fields() | {"bash_command"})
return cls.__serialized_fields


class GoogleLink(BaseOperatorLink):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/serialization/test_dag_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"_operator_extra_links": [{"airflow.utils.tests.CustomOpLink": {}}],
"ui_color": "#fff",
"ui_fgcolor": "#000",
"template_fields": [],
"template_fields": ['bash_command'],
"_task_type": "CustomOperator",
"_task_module": "airflow.utils.tests",
},
Expand Down

0 comments on commit 5209665

Please sign in to comment.