We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
UndefinedJinjaVariablesRule fails on non-standard python objects
**Apache Airflow version**: 1.10.14

**Kubernetes version (if you are using kubernetes)** (use `kubectl version`):

**Environment**: 

- **Cloud provider or hardware configuration**: X
- **OS** (e.g. from /etc/os-release): X
- **Kernel** (e.g. `uname -a`): X
- **Install tools**: X
- **Others**: X

**What happened**:

The `UndefinedJinjaVariablesRule` appears to expect non-standard python objects to have a `template_fields` attribute, when many (`pathlib.Path`, `None`) do not.

<details><summary>Path example</summary>

```python
========================================================================================================================================================== STATUS ==========================================================================================================================================================

Check for latest versions of apache-airflow and checker...........................................................................................................................................................................................................................................................SUCCESS
Remove airflow.AirflowMacroPlugin class...........................................................................................................................................................................................................................................................................SUCCESS
Chain between DAG and operator not allowed........................................................................................................................................................................................................................................................................SUCCESS
Connection.conn_id is not unique..................................................................................................................................................................................................................................................................................SUCCESS
Connection.conn_type is not nullable..............................................................................................................................................................................................................................................................................SUCCESS
Ensure users are not using custom metaclasses in custom operators.................................................................................................................................................................................................................................................SUCCESS
Fernet is enabled by default......................................................................................................................................................................................................................................................................................FAIL
GCP service account key deprecation...............................................................................................................................................................................................................................................................................SUCCESS
Unify hostname_callable option in core section....................................................................................................................................................................................................................................................................FAIL
Changes in import paths of hooks, operators, sensors and others...................................................................................................................................................................................................................................................SUCCESS
Users must delete deprecated configs for KubernetesExecutor.......................................................................................................................................................................................................................................................FAIL
Legacy UI is deprecated by default................................................................................................................................................................................................................................................................................SUCCESS
Logging configuration has been moved to new section...............................................................................................................................................................................................................................................................FAIL
Removal of Mesos Executor.........................................................................................................................................................................................................................................................................................SUCCESS
No additional argument allowed in BaseOperator....................................................................................................................................................................................................................................................................SUCCESS
Users must set a kubernetes.pod_template_file value...............................................................................................................................................................................................................................................................SKIPPED
SendGrid email uses old airflow.contrib module....................................................................................................................................................................................................................................................................SUCCESS
Changes in import path of remote task handlers....................................................................................................................................................................................................................................................................SUCCESS
Traceback (most recent call last):
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/bin/airflow", line 37, in <module>
    args.func(args)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/checker.py", line 88, in run
    all_problems = check_upgrade(formatter, rules)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/checker.py", line 37, in check_upgrade
    rule_status = RuleStatus.from_rule(rule)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/problem.py", line 44, in from_rule
    result = rule.check()
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 141, in check
    dag_messages = self.iterate_over_dag_tasks(dag)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 128, in iterate_over_dag_tasks
    error_messages = self.iterate_over_template_fields(task)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 117, in iterate_over_template_fields
    self._check_rendered_content(rendered_content, set())
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 63, in _check_rendered_content
    debug_error_messages.update(self._check_rendered_content(value))
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 69, in _check_rendered_content
    return self._nested_check_rendered(rendered_content, seen_oids)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 75, in _nested_check_rendered
    nested_template_fields = rendered_content.template_fields
AttributeError: 'PosixPath' object has no attribute 'template_fields'
```

</details>

<details><summary>None example</summary>

```python
========================================================================================================================================================== STATUS ==========================================================================================================================================================

Check for latest versions of apache-airflow and checker...........................................................................................................................................................................................................................................................SUCCESS
Remove airflow.AirflowMacroPlugin class...........................................................................................................................................................................................................................................................................SUCCESS
Chain between DAG and operator not allowed........................................................................................................................................................................................................................................................................SUCCESS
Connection.conn_id is not unique..................................................................................................................................................................................................................................................................................SUCCESS
Connection.conn_type is not nullable..............................................................................................................................................................................................................................................................................SUCCESS
Ensure users are not using custom metaclasses in custom operators.................................................................................................................................................................................................................................................SUCCESS
Fernet is enabled by default......................................................................................................................................................................................................................................................................................FAIL
GCP service account key deprecation...............................................................................................................................................................................................................................................................................SUCCESS
Unify hostname_callable option in core section....................................................................................................................................................................................................................................................................FAIL
Changes in import paths of hooks, operators, sensors and others...................................................................................................................................................................................................................................................SUCCESS
Users must delete deprecated configs for KubernetesExecutor.......................................................................................................................................................................................................................................................FAIL
Legacy UI is deprecated by default................................................................................................................................................................................................................................................................................SUCCESS
Logging configuration has been moved to new section...............................................................................................................................................................................................................................................................FAIL
Removal of Mesos Executor.........................................................................................................................................................................................................................................................................................SUCCESS
No additional argument allowed in BaseOperator....................................................................................................................................................................................................................................................................SUCCESS
Users must set a kubernetes.pod_template_file value...............................................................................................................................................................................................................................................................SKIPPED
SendGrid email uses old airflow.contrib module....................................................................................................................................................................................................................................................................SUCCESS
Changes in import path of remote task handlers....................................................................................................................................................................................................................................................................SUCCESS
Traceback (most recent call last):
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/bin/airflow", line 37, in <module>
    args.func(args)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/checker.py", line 88, in run
    all_problems = check_upgrade(formatter, rules)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/checker.py", line 37, in check_upgrade
    rule_status = RuleStatus.from_rule(rule)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/problem.py", line 44, in from_rule
    result = rule.check()
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 146, in check
    dag_messages = self.iterate_over_dag_tasks(dag)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 130, in iterate_over_dag_tasks
    error_messages = self.iterate_over_template_fields(task)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 118, in iterate_over_template_fields
    self._check_rendered_content(rendered_content, set())
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 64, in _check_rendered_content
    debug_error_messages.update(self._check_rendered_content(value))
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 70, in _check_rendered_content
    return self._nested_check_rendered(rendered_content, seen_oids)
  File "/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py", line 76, in _nested_check_rendered
    nested_template_fields = rendered_content.template_fields
AttributeError: 'NoneType' object has no attribute 'template_fields'
```

</details>

**What you expected to happen**:

I expect these types to be handled appropriately by the upgrade rule and not assume that a `template_fields` attribute exists on them.

**How to reproduce it**:

Create a simple DAG with a `PythonOperator` task that has `op_kwargs: {"foo": None}` and run the upgrade check.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `airflow/upgrade/rules/undefined_jinja_varaibles.py`
Content:
```
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements.  See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership.  The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License.  You may obtain a copy of the License at
8 #
9 #   http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied.  See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17 
18 from __future__ import absolute_import
19 
20 import re
21 
22 import jinja2
23 import six
24 
25 from airflow import conf
26 from airflow.models import DagBag, TaskInstance
27 from airflow.upgrade.rules.base_rule import BaseRule
28 from airflow.utils import timezone
29 
30 
31 class UndefinedJinjaVariablesRule(BaseRule):
32 
33     title = "Jinja Template Variables cannot be undefined"
34 
35     description = """\
36 The default behavior for DAG's Jinja templates has changed. Now, more restrictive validation
37 of non-existent variables is applied - `jinja2.StrictUndefined`.
38 
39 The user should do either of the following to fix this -
40 1. Fix the Jinja Templates by defining every variable or providing default values
41 2. Explicitly declare `template_undefined=jinja2.Undefined` while defining the DAG
42 """
43 
44     def _check_rendered_content(self, rendered_content, seen_oids=None):
45         """Replicates the logic in BaseOperator.render_template() to
46         cover all the cases needed to be checked.
47         """
48         if isinstance(rendered_content, six.string_types):
49             return set(re.findall(r"{{(.*?)}}", rendered_content))
50 
51         elif isinstance(rendered_content, (int, float, bool)):
52             return set()
53 
54         elif isinstance(rendered_content, (tuple, list, set)):
55             debug_error_messages = set()
56             for element in rendered_content:
57                 debug_error_messages.update(self._check_rendered_content(element))
58             return debug_error_messages
59 
60         elif isinstance(rendered_content, dict):
61             debug_error_messages = set()
62             for key, value in rendered_content.items():
63                 debug_error_messages.update(self._check_rendered_content(value))
64             return debug_error_messages
65 
66         else:
67             if seen_oids is None:
68                 seen_oids = set()
69             return self._nested_check_rendered(rendered_content, seen_oids)
70 
71     def _nested_check_rendered(self, rendered_content, seen_oids):
72         debug_error_messages = set()
73         if id(rendered_content) not in seen_oids:
74             seen_oids.add(id(rendered_content))
75             nested_template_fields = rendered_content.template_fields
76             for attr_name in nested_template_fields:
77                 nested_rendered_content = getattr(rendered_content, attr_name)
78 
79                 if nested_rendered_content:
80                     errors = list(
81                         self._check_rendered_content(nested_rendered_content, seen_oids)
82                     )
83                     for i in range(len(errors)):
84                         errors[i].strip()
85                         errors[i] += " NestedTemplateField={}".format(attr_name)
86                     debug_error_messages.update(errors)
87         return debug_error_messages
88 
89     def _render_task_content(self, task, content, context):
90         completed_rendering = False
91         errors_while_rendering = []
92         while not completed_rendering:
93             # Catch errors such as {{ object.element }} where
94             # object is not defined
95             try:
96                 renderend_content = task.render_template(content, context)
97                 completed_rendering = True
98             except Exception as e:
99                 undefined_variable = re.sub(" is undefined", "", str(e))
100                 undefined_variable = re.sub("'", "", undefined_variable)
101                 context[undefined_variable] = dict()
102                 message = "Could not find the object '{}'".format(undefined_variable)
103                 errors_while_rendering.append(message)
104         return renderend_content, errors_while_rendering
105 
106     def iterate_over_template_fields(self, task):
107         messages = {}
108         task_instance = TaskInstance(task=task, execution_date=timezone.utcnow())
109         context = task_instance.get_template_context()
110         for attr_name in task.template_fields:
111             content = getattr(task, attr_name)
112             if content:
113                 rendered_content, errors_while_rendering = self._render_task_content(
114                     task, content, context
115                 )
116                 debug_error_messages = list(
117                     self._check_rendered_content(rendered_content, set())
118                 )
119                 messages[attr_name] = errors_while_rendering + debug_error_messages
120 
121         return messages
122 
123     def iterate_over_dag_tasks(self, dag):
124         dag.template_undefined = jinja2.DebugUndefined
125         tasks = dag.tasks
126         messages = {}
127         for task in tasks:
128             error_messages = self.iterate_over_template_fields(task)
129             messages[task.task_id] = error_messages
130         return messages
131 
132     def check(self, dagbag=None):
133         if not dagbag:
134             dag_folder = conf.get("core", "dags_folder")
135             dagbag = DagBag(dag_folder)
136         dags = dagbag.dags
137         messages = []
138         for dag_id, dag in dags.items():
139             if dag.template_undefined:
140                 continue
141             dag_messages = self.iterate_over_dag_tasks(dag)
142 
143             for task_id, task_messages in dag_messages.items():
144                 for attr_name, error_messages in task_messages.items():
145                     for error_message in error_messages:
146                         message = (
147                             "Possible UndefinedJinjaVariable -> DAG: {}, Task: {}, "
148                             "Attribute: {}, Error: {}".format(
149                                 dag_id, task_id, attr_name, error_message.strip()
150                             )
151                         )
152                         messages.append(message)
153         return messages
154
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/airflow/upgrade/rules/undefined_jinja_varaibles.py b/airflow/upgrade/rules/undefined_jinja_varaibles.py
--- a/airflow/upgrade/rules/undefined_jinja_varaibles.py
+++ b/airflow/upgrade/rules/undefined_jinja_varaibles.py
@@ -48,9 +48,6 @@
         if isinstance(rendered_content, six.string_types):
             return set(re.findall(r"{{(.*?)}}", rendered_content))
 
-        elif isinstance(rendered_content, (int, float, bool)):
-            return set()
-
         elif isinstance(rendered_content, (tuple, list, set)):
             debug_error_messages = set()
             for element in rendered_content:
@@ -63,11 +60,15 @@
                 debug_error_messages.update(self._check_rendered_content(value))
             return debug_error_messages
 
-        else:
+        elif hasattr(rendered_content, "template_fields"):
             if seen_oids is None:
                 seen_oids = set()
             return self._nested_check_rendered(rendered_content, seen_oids)
 
+        else:
+            # Rendered content is not actually rendered
+            return set()
+
     def _nested_check_rendered(self, rendered_content, seen_oids):
         debug_error_messages = set()
         if id(rendered_content) not in seen_oids:

{"golden_diff": "diff --git a/airflow/upgrade/rules/undefined_jinja_varaibles.py b/airflow/upgrade/rules/undefined_jinja_varaibles.py\n--- a/airflow/upgrade/rules/undefined_jinja_varaibles.py\n+++ b/airflow/upgrade/rules/undefined_jinja_varaibles.py\n@@ -48,9 +48,6 @@\n         if isinstance(rendered_content, six.string_types):\n             return set(re.findall(r\"{{(.*?)}}\", rendered_content))\n \n-        elif isinstance(rendered_content, (int, float, bool)):\n-            return set()\n-\n         elif isinstance(rendered_content, (tuple, list, set)):\n             debug_error_messages = set()\n             for element in rendered_content:\n@@ -63,11 +60,15 @@\n                 debug_error_messages.update(self._check_rendered_content(value))\n             return debug_error_messages\n \n-        else:\n+        elif hasattr(rendered_content, \"template_fields\"):\n             if seen_oids is None:\n                 seen_oids = set()\n             return self._nested_check_rendered(rendered_content, seen_oids)\n \n+        else:\n+            # Rendered content is not actually rendered\n+            return set()\n+\n     def _nested_check_rendered(self, rendered_content, seen_oids):\n         debug_error_messages = set()\n         if id(rendered_content) not in seen_oids:\n", "issue": "UndefinedJinjaVariablesRule fails on non-standard python objects\n**Apache Airflow version**: 1.10.14\r\n\r\n**Kubernetes version (if you are using kubernetes)** (use `kubectl version`):\r\n\r\n**Environment**: \r\n\r\n- **Cloud provider or hardware configuration**: X\r\n- **OS** (e.g. from /etc/os-release): X\r\n- **Kernel** (e.g. `uname -a`): X\r\n- **Install tools**: X\r\n- **Others**: X\r\n\r\n**What happened**:\r\n\r\nThe `UndefinedJinjaVariablesRule` appears to expect non-standard python objects to have a `template_fields` attribute, when many (`pathlib.Path`, `None`) do not.\r\n\r\n<details><summary>Path example</summary>\r\n\r\n```python\r\n========================================================================================================================================================== STATUS ==========================================================================================================================================================\r\n\r\nCheck for latest versions of apache-airflow and checker...........................................................................................................................................................................................................................................................SUCCESS\r\nRemove airflow.AirflowMacroPlugin class...........................................................................................................................................................................................................................................................................SUCCESS\r\nChain between DAG and operator not allowed........................................................................................................................................................................................................................................................................SUCCESS\r\nConnection.conn_id is not unique..................................................................................................................................................................................................................................................................................SUCCESS\r\nConnection.conn_type is not nullable..............................................................................................................................................................................................................................................................................SUCCESS\r\nEnsure users are not using custom metaclasses in custom operators.................................................................................................................................................................................................................................................SUCCESS\r\nFernet is enabled by default......................................................................................................................................................................................................................................................................................FAIL\r\nGCP service account key deprecation...............................................................................................................................................................................................................................................................................SUCCESS\r\nUnify hostname_callable option in core section....................................................................................................................................................................................................................................................................FAIL\r\nChanges in import paths of hooks, operators, sensors and others...................................................................................................................................................................................................................................................SUCCESS\r\nUsers must delete deprecated configs for KubernetesExecutor.......................................................................................................................................................................................................................................................FAIL\r\nLegacy UI is deprecated by default................................................................................................................................................................................................................................................................................SUCCESS\r\nLogging configuration has been moved to new section...............................................................................................................................................................................................................................................................FAIL\r\nRemoval of Mesos Executor.........................................................................................................................................................................................................................................................................................SUCCESS\r\nNo additional argument allowed in BaseOperator....................................................................................................................................................................................................................................................................SUCCESS\r\nUsers must set a kubernetes.pod_template_file value...............................................................................................................................................................................................................................................................SKIPPED\r\nSendGrid email uses old airflow.contrib module....................................................................................................................................................................................................................................................................SUCCESS\r\nChanges in import path of remote task handlers....................................................................................................................................................................................................................................................................SUCCESS\r\nTraceback (most recent call last):\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/bin/airflow\", line 37, in <module>\r\n    args.func(args)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/checker.py\", line 88, in run\r\n    all_problems = check_upgrade(formatter, rules)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/checker.py\", line 37, in check_upgrade\r\n    rule_status = RuleStatus.from_rule(rule)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/problem.py\", line 44, in from_rule\r\n    result = rule.check()\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 141, in check\r\n    dag_messages = self.iterate_over_dag_tasks(dag)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 128, in iterate_over_dag_tasks\r\n    error_messages = self.iterate_over_template_fields(task)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 117, in iterate_over_template_fields\r\n    self._check_rendered_content(rendered_content, set())\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 63, in _check_rendered_content\r\n    debug_error_messages.update(self._check_rendered_content(value))\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 69, in _check_rendered_content\r\n    return self._nested_check_rendered(rendered_content, seen_oids)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 75, in _nested_check_rendered\r\n    nested_template_fields = rendered_content.template_fields\r\nAttributeError: 'PosixPath' object has no attribute 'template_fields'\r\n```\r\n\r\n</details>\r\n\r\n<details><summary>None example</summary>\r\n\r\n```python\r\n========================================================================================================================================================== STATUS ==========================================================================================================================================================\r\n\r\nCheck for latest versions of apache-airflow and checker...........................................................................................................................................................................................................................................................SUCCESS\r\nRemove airflow.AirflowMacroPlugin class...........................................................................................................................................................................................................................................................................SUCCESS\r\nChain between DAG and operator not allowed........................................................................................................................................................................................................................................................................SUCCESS\r\nConnection.conn_id is not unique..................................................................................................................................................................................................................................................................................SUCCESS\r\nConnection.conn_type is not nullable..............................................................................................................................................................................................................................................................................SUCCESS\r\nEnsure users are not using custom metaclasses in custom operators.................................................................................................................................................................................................................................................SUCCESS\r\nFernet is enabled by default......................................................................................................................................................................................................................................................................................FAIL\r\nGCP service account key deprecation...............................................................................................................................................................................................................................................................................SUCCESS\r\nUnify hostname_callable option in core section....................................................................................................................................................................................................................................................................FAIL\r\nChanges in import paths of hooks, operators, sensors and others...................................................................................................................................................................................................................................................SUCCESS\r\nUsers must delete deprecated configs for KubernetesExecutor.......................................................................................................................................................................................................................................................FAIL\r\nLegacy UI is deprecated by default................................................................................................................................................................................................................................................................................SUCCESS\r\nLogging configuration has been moved to new section...............................................................................................................................................................................................................................................................FAIL\r\nRemoval of Mesos Executor.........................................................................................................................................................................................................................................................................................SUCCESS\r\nNo additional argument allowed in BaseOperator....................................................................................................................................................................................................................................................................SUCCESS\r\nUsers must set a kubernetes.pod_template_file value...............................................................................................................................................................................................................................................................SKIPPED\r\nSendGrid email uses old airflow.contrib module....................................................................................................................................................................................................................................................................SUCCESS\r\nChanges in import path of remote task handlers....................................................................................................................................................................................................................................................................SUCCESS\r\nTraceback (most recent call last):\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/bin/airflow\", line 37, in <module>\r\n    args.func(args)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/checker.py\", line 88, in run\r\n    all_problems = check_upgrade(formatter, rules)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/checker.py\", line 37, in check_upgrade\r\n    rule_status = RuleStatus.from_rule(rule)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/problem.py\", line 44, in from_rule\r\n    result = rule.check()\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 146, in check\r\n    dag_messages = self.iterate_over_dag_tasks(dag)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 130, in iterate_over_dag_tasks\r\n    error_messages = self.iterate_over_template_fields(task)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 118, in iterate_over_template_fields\r\n    self._check_rendered_content(rendered_content, set())\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 64, in _check_rendered_content\r\n    debug_error_messages.update(self._check_rendered_content(value))\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 70, in _check_rendered_content\r\n    return self._nested_check_rendered(rendered_content, seen_oids)\r\n  File \"/Users/madison/programs/anaconda3/envs/memphis-airflow/lib/python3.8/site-packages/airflow/upgrade/rules/undefined_jinja_varaibles.py\", line 76, in _nested_check_rendered\r\n    nested_template_fields = rendered_content.template_fields\r\nAttributeError: 'NoneType' object has no attribute 'template_fields'\r\n```\r\n\r\n</details>\r\n\r\n**What you expected to happen**:\r\n\r\nI expect these types to be handled appropriately by the upgrade rule and not assume that a `template_fields` attribute exists on them.\r\n\r\n**How to reproduce it**:\r\n\r\nCreate a simple DAG with a `PythonOperator` task that has `op_kwargs: {\"foo\": None}` and run the upgrade check.\n", "before_files": [{"content": "# Licensed to the Apache Software Foundation (ASF) under one\n# or more contributor license agreements.  See the NOTICE file\n# distributed with this work for additional information\n# regarding copyright ownership.  The ASF licenses this file\n# to you under the Apache License, Version 2.0 (the\n# \"License\"); you may not use this file except in compliance\n# with the License.  You may obtain a copy of the License at\n#\n#   http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing,\n# software distributed under the License is distributed on an\n# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n# KIND, either express or implied.  See the License for the\n# specific language governing permissions and limitations\n# under the License.\n\nfrom __future__ import absolute_import\n\nimport re\n\nimport jinja2\nimport six\n\nfrom airflow import conf\nfrom airflow.models import DagBag, TaskInstance\nfrom airflow.upgrade.rules.base_rule import BaseRule\nfrom airflow.utils import timezone\n\n\nclass UndefinedJinjaVariablesRule(BaseRule):\n\n    title = \"Jinja Template Variables cannot be undefined\"\n\n    description = \"\"\"\\\nThe default behavior for DAG's Jinja templates has changed. Now, more restrictive validation\nof non-existent variables is applied - `jinja2.StrictUndefined`.\n\nThe user should do either of the following to fix this -\n1. Fix the Jinja Templates by defining every variable or providing default values\n2. Explicitly declare `template_undefined=jinja2.Undefined` while defining the DAG\n\"\"\"\n\n    def _check_rendered_content(self, rendered_content, seen_oids=None):\n        \"\"\"Replicates the logic in BaseOperator.render_template() to\n        cover all the cases needed to be checked.\n        \"\"\"\n        if isinstance(rendered_content, six.string_types):\n            return set(re.findall(r\"{{(.*?)}}\", rendered_content))\n\n        elif isinstance(rendered_content, (int, float, bool)):\n            return set()\n\n        elif isinstance(rendered_content, (tuple, list, set)):\n            debug_error_messages = set()\n            for element in rendered_content:\n                debug_error_messages.update(self._check_rendered_content(element))\n            return debug_error_messages\n\n        elif isinstance(rendered_content, dict):\n            debug_error_messages = set()\n            for key, value in rendered_content.items():\n                debug_error_messages.update(self._check_rendered_content(value))\n            return debug_error_messages\n\n        else:\n            if seen_oids is None:\n                seen_oids = set()\n            return self._nested_check_rendered(rendered_content, seen_oids)\n\n    def _nested_check_rendered(self, rendered_content, seen_oids):\n        debug_error_messages = set()\n        if id(rendered_content) not in seen_oids:\n            seen_oids.add(id(rendered_content))\n            nested_template_fields = rendered_content.template_fields\n            for attr_name in nested_template_fields:\n                nested_rendered_content = getattr(rendered_content, attr_name)\n\n                if nested_rendered_content:\n                    errors = list(\n                        self._check_rendered_content(nested_rendered_content, seen_oids)\n                    )\n                    for i in range(len(errors)):\n                        errors[i].strip()\n                        errors[i] += \" NestedTemplateField={}\".format(attr_name)\n                    debug_error_messages.update(errors)\n        return debug_error_messages\n\n    def _render_task_content(self, task, content, context):\n        completed_rendering = False\n        errors_while_rendering = []\n        while not completed_rendering:\n            # Catch errors such as {{ object.element }} where\n            # object is not defined\n            try:\n                renderend_content = task.render_template(content, context)\n                completed_rendering = True\n            except Exception as e:\n                undefined_variable = re.sub(\" is undefined\", \"\", str(e))\n                undefined_variable = re.sub(\"'\", \"\", undefined_variable)\n                context[undefined_variable] = dict()\n                message = \"Could not find the object '{}'\".format(undefined_variable)\n                errors_while_rendering.append(message)\n        return renderend_content, errors_while_rendering\n\n    def iterate_over_template_fields(self, task):\n        messages = {}\n        task_instance = TaskInstance(task=task, execution_date=timezone.utcnow())\n        context = task_instance.get_template_context()\n        for attr_name in task.template_fields:\n            content = getattr(task, attr_name)\n            if content:\n                rendered_content, errors_while_rendering = self._render_task_content(\n                    task, content, context\n                )\n                debug_error_messages = list(\n                    self._check_rendered_content(rendered_content, set())\n                )\n                messages[attr_name] = errors_while_rendering + debug_error_messages\n\n        return messages\n\n    def iterate_over_dag_tasks(self, dag):\n        dag.template_undefined = jinja2.DebugUndefined\n        tasks = dag.tasks\n        messages = {}\n        for task in tasks:\n            error_messages = self.iterate_over_template_fields(task)\n            messages[task.task_id] = error_messages\n        return messages\n\n    def check(self, dagbag=None):\n        if not dagbag:\n            dag_folder = conf.get(\"core\", \"dags_folder\")\n            dagbag = DagBag(dag_folder)\n        dags = dagbag.dags\n        messages = []\n        for dag_id, dag in dags.items():\n            if dag.template_undefined:\n                continue\n            dag_messages = self.iterate_over_dag_tasks(dag)\n\n            for task_id, task_messages in dag_messages.items():\n                for attr_name, error_messages in task_messages.items():\n                    for error_message in error_messages:\n                        message = (\n                            \"Possible UndefinedJinjaVariable -> DAG: {}, Task: {}, \"\n                            \"Attribute: {}, Error: {}\".format(\n                                dag_id, task_id, attr_name, error_message.strip()\n                            )\n                        )\n                        messages.append(message)\n        return messages\n", "path": "airflow/upgrade/rules/undefined_jinja_varaibles.py"}], "after_files": [{"content": "# Licensed to the Apache Software Foundation (ASF) under one\n# or more contributor license agreements.  See the NOTICE file\n# distributed with this work for additional information\n# regarding copyright ownership.  The ASF licenses this file\n# to you under the Apache License, Version 2.0 (the\n# \"License\"); you may not use this file except in compliance\n# with the License.  You may obtain a copy of the License at\n#\n#   http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing,\n# software distributed under the License is distributed on an\n# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n# KIND, either express or implied.  See the License for the\n# specific language governing permissions and limitations\n# under the License.\n\nfrom __future__ import absolute_import\n\nimport re\n\nimport jinja2\nimport six\n\nfrom airflow import conf\nfrom airflow.models import DagBag, TaskInstance\nfrom airflow.upgrade.rules.base_rule import BaseRule\nfrom airflow.utils import timezone\n\n\nclass UndefinedJinjaVariablesRule(BaseRule):\n\n    title = \"Jinja Template Variables cannot be undefined\"\n\n    description = \"\"\"\\\nThe default behavior for DAG's Jinja templates has changed. Now, more restrictive validation\nof non-existent variables is applied - `jinja2.StrictUndefined`.\n\nThe user should do either of the following to fix this -\n1. Fix the Jinja Templates by defining every variable or providing default values\n2. Explicitly declare `template_undefined=jinja2.Undefined` while defining the DAG\n\"\"\"\n\n    def _check_rendered_content(self, rendered_content, seen_oids=None):\n        \"\"\"Replicates the logic in BaseOperator.render_template() to\n        cover all the cases needed to be checked.\n        \"\"\"\n        if isinstance(rendered_content, six.string_types):\n            return set(re.findall(r\"{{(.*?)}}\", rendered_content))\n\n        elif isinstance(rendered_content, (tuple, list, set)):\n            debug_error_messages = set()\n            for element in rendered_content:\n                debug_error_messages.update(self._check_rendered_content(element))\n            return debug_error_messages\n\n        elif isinstance(rendered_content, dict):\n            debug_error_messages = set()\n            for key, value in rendered_content.items():\n                debug_error_messages.update(self._check_rendered_content(value))\n            return debug_error_messages\n\n        elif hasattr(rendered_content, \"template_fields\"):\n            if seen_oids is None:\n                seen_oids = set()\n            return self._nested_check_rendered(rendered_content, seen_oids)\n\n        else:\n            # Rendered content is not actually rendered\n            return set()\n\n    def _nested_check_rendered(self, rendered_content, seen_oids):\n        debug_error_messages = set()\n        if id(rendered_content) not in seen_oids:\n            seen_oids.add(id(rendered_content))\n            nested_template_fields = rendered_content.template_fields\n            for attr_name in nested_template_fields:\n                nested_rendered_content = getattr(rendered_content, attr_name)\n\n                if nested_rendered_content:\n                    errors = list(\n                        self._check_rendered_content(nested_rendered_content, seen_oids)\n                    )\n                    for i in range(len(errors)):\n                        errors[i].strip()\n                        errors[i] += \" NestedTemplateField={}\".format(attr_name)\n                    debug_error_messages.update(errors)\n        return debug_error_messages\n\n    def _render_task_content(self, task, content, context):\n        completed_rendering = False\n        errors_while_rendering = []\n        while not completed_rendering:\n            # Catch errors such as {{ object.element }} where\n            # object is not defined\n            try:\n                renderend_content = task.render_template(content, context)\n                completed_rendering = True\n            except Exception as e:\n                undefined_variable = re.sub(\" is undefined\", \"\", str(e))\n                undefined_variable = re.sub(\"'\", \"\", undefined_variable)\n                context[undefined_variable] = dict()\n                message = \"Could not find the object '{}'\".format(undefined_variable)\n                errors_while_rendering.append(message)\n        return renderend_content, errors_while_rendering\n\n    def iterate_over_template_fields(self, task):\n        messages = {}\n        task_instance = TaskInstance(task=task, execution_date=timezone.utcnow())\n        context = task_instance.get_template_context()\n        for attr_name in task.template_fields:\n            content = getattr(task, attr_name)\n            if content:\n                rendered_content, errors_while_rendering = self._render_task_content(\n                    task, content, context\n                )\n                debug_error_messages = list(\n                    self._check_rendered_content(rendered_content, set())\n                )\n                messages[attr_name] = errors_while_rendering + debug_error_messages\n\n        return messages\n\n    def iterate_over_dag_tasks(self, dag):\n        dag.template_undefined = jinja2.DebugUndefined\n        tasks = dag.tasks\n        messages = {}\n        for task in tasks:\n            error_messages = self.iterate_over_template_fields(task)\n            messages[task.task_id] = error_messages\n        return messages\n\n    def check(self, dagbag=None):\n        if not dagbag:\n            dag_folder = conf.get(\"core\", \"dags_folder\")\n            dagbag = DagBag(dag_folder)\n        dags = dagbag.dags\n        messages = []\n        for dag_id, dag in dags.items():\n            if dag.template_undefined:\n                continue\n            dag_messages = self.iterate_over_dag_tasks(dag)\n\n            for task_id, task_messages in dag_messages.items():\n                for attr_name, error_messages in task_messages.items():\n                    for error_message in error_messages:\n                        message = (\n                            \"Possible UndefinedJinjaVariable -> DAG: {}, Task: {}, \"\n                            \"Attribute: {}, Error: {}\".format(\n                                dag_id, task_id, attr_name, error_message.strip()\n                            )\n                        )\n                        messages.append(message)\n        return messages\n", "path": "airflow/upgrade/rules/undefined_jinja_varaibles.py"}]}