We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
influxdb_query fails with 'NoneType' object is not iterable
<!---
Verify first that your issue/request is not already reported on GitHub.
THIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.
Also test if the latest release, and devel branch are affected too.
ALWAYS add information AFTER (OUTSIDE) these html comments.
Otherwise it may end up being automatically closed by our bot. -->

##### SUMMARY
influxdb_query throws an error when trying to create/drop a continuous query in influxdb using influxdb_query module but the continuous query gets created/deleted successfully nevertheless.

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
<!--- Insert, BELOW THIS COMMENT, the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path-->
influxdb_query

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.5.5
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/plamen/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0]
```

##### CONFIGURATION
<!--- If using Ansible 2.4 or above, paste, BELOW THIS COMMENT, the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).-->
DEFAULT_STDOUT_CALLBACK(/etc/ansible/ansible.cfg) = skippy
RETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = False

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.-->
Arch Linux

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: InfluxDB | Create InfluxDB DB
  influxdb_database:
    database_name: "mydb"

- name: InfluxDB | Create InfluxDB Retention Policy
  influxdb_retention_policy:
    database_name: "mydb"
    policy_name: "aggregated"
    default: no
    replication: 1
    duration: "400d"

- name: InfluxDB | Create InfluxDB Continuous Query
  influxdb_query:
    database_name: "mydb"
    query: "CREATE CONTINUOUS QUERY host_router ON mydb BEGIN select sum(activeQueuedInteractions) as activeQueuedInteractions, sum(loggedUsers) as loggedUsers INTO aggregated.host_router FROM router GROUP BY hostname, time(10s, 1m) END"
```
I get the same result when I try to drop the continuous query - the continuous query gets deleted but ansible fails with the same error
```yaml
- name: InfluxDB | Drop InfluxDB Continuous Queries
  influxdb_query:
    database_name: "{{ cluster_name }}"
    query: "DROP CONTINUOUS QUERY host_router   ON {{ cluster_name }}"
```



<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
The continuous query should be created successfully and Ansible should not fail.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
It looks like influxdb_query manages to create/drop the continuous query but it throws the following error:
<!--- Paste verbatim command output between quotes below -->
```
ERROR! Unexpected Exception, this is probably a bug: 'NoneType' object is not iterable
the full traceback was:

Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 118, in <module>
    exit_code = cli.run()
  File "/usr/lib/python3.6/site-packages/ansible/cli/playbook.py", line 122, in run
    results = pbex.run()
  File "/usr/lib/python3.6/site-packages/ansible/executor/playbook_executor.py", line 159, in run
    result = self._tqm.run(play=play)
  File "/usr/lib/python3.6/site-packages/ansible/executor/task_queue_manager.py", line 289, in run
    play_return = strategy.run(iterator, play_context)
  File "/usr/lib/python3.6/site-packages/ansible/plugins/strategy/linear.py", line 321, in run
    results += self._wait_on_pending_results(iterator)
  File "/usr/lib/python3.6/site-packages/ansible/plugins/strategy/__init__.py", line 674, in _wait_on_pending_results
    results = self._process_pending_results(iterator)
  File "/usr/lib/python3.6/site-packages/ansible/plugins/strategy/__init__.py", line 117, in inner
    results = func(self, iterator, one_pass=one_pass, max_passes=max_passes)
  File "/usr/lib/python3.6/site-packages/ansible/plugins/strategy/__init__.py", line 447, in _process_pending_results
    if task_result.is_failed() or task_result.is_unreachable():
  File "/usr/lib/python3.6/site-packages/ansible/executor/task_result.py", line 59, in is_failed
    'results' in self._result and True in [True for x in self._result['results'] if 'failed_when_result' in x]:
TypeError: 'NoneType' object is not iterable

```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/ansible/modules/database/influxdb/influxdb_query.py`
Content:
```
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright (c) 2017, René Moser <mail@renemoser.net>
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5 
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8 
9 
10 ANSIBLE_METADATA = {'metadata_version': '1.1',
11                     'status': ['preview'],
12                     'supported_by': 'community'}
13 
14 
15 DOCUMENTATION = '''
16 ---
17 module: influxdb_query
18 short_description: Query data points from InfluxDB.
19 description:
20   - Query data points from InfluxDB.
21 version_added: 2.5
22 author: "René Moser (@resmo)"
23 requirements:
24   - "python >= 2.6"
25   - "influxdb >= 0.9"
26 options:
27   query:
28     description:
29       - Query to be executed.
30     required: true
31   database_name:
32     description:
33       - Name of the database.
34     required: true
35 extends_documentation_fragment: influxdb
36 '''
37 
38 EXAMPLES = r'''
39 - name: Query connections
40   influxdb_query:
41     hostname: "{{ influxdb_ip_address }}"
42     database_name: "{{ influxdb_database_name }}"
43     query: "select mean(value) from connections"
44   register: connection
45 
46 - name: Query connections with tags filters
47   influxdb_query:
48     hostname: "{{ influxdb_ip_address }}"
49     database_name: "{{ influxdb_database_name }}"
50     query: "select mean(value) from connections where region='zue01' and host='server01'"
51   register: connection
52 
53 - name: Print results from the query
54   debug:
55     var: connection.results
56 '''
57 
58 RETURN = '''
59 results:
60   description: Result from the query
61   returned: success
62   type: list
63   sample:
64     - mean: 1245.5333333333333
65       time: "1970-01-01T00:00:00Z"
66 '''
67 
68 from ansible.module_utils.basic import AnsibleModule
69 from ansible.module_utils._text import to_native
70 from ansible.module_utils.influxdb import InfluxDb
71 
72 
73 class AnsibleInfluxDBRead(InfluxDb):
74 
75     def read_by_query(self, query):
76         client = self.connect_to_influxdb()
77         try:
78             rs = client.query(query)
79             if rs:
80                 return list(rs.get_points())
81         except Exception as e:
82             self.module.fail_json(msg=to_native(e))
83 
84 
85 def main():
86     argument_spec = InfluxDb.influxdb_argument_spec()
87     argument_spec.update(
88         query=dict(type='str', required=True),
89         database_name=dict(required=True, type='str'),
90     )
91     module = AnsibleModule(
92         argument_spec=argument_spec,
93         supports_check_mode=True
94     )
95 
96     influx = AnsibleInfluxDBRead(module)
97     query = module.params.get('query')
98     results = influx.read_by_query(query)
99     module.exit_json(changed=True, results=results)
100 
101 
102 if __name__ == '__main__':
103     main()
104
```
--- 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/lib/ansible/modules/database/influxdb/influxdb_query.py b/lib/ansible/modules/database/influxdb/influxdb_query.py
--- a/lib/ansible/modules/database/influxdb/influxdb_query.py
+++ b/lib/ansible/modules/database/influxdb/influxdb_query.py
@@ -52,11 +52,11 @@
 
 - name: Print results from the query
   debug:
-    var: connection.results
+    var: connection.query_results
 '''
 
 RETURN = '''
-results:
+query_results:
   description: Result from the query
   returned: success
   type: list
@@ -96,7 +96,7 @@
     influx = AnsibleInfluxDBRead(module)
     query = module.params.get('query')
     results = influx.read_by_query(query)
-    module.exit_json(changed=True, results=results)
+    module.exit_json(changed=True, query_results=results)
 
 
 if __name__ == '__main__':

{"golden_diff": "diff --git a/lib/ansible/modules/database/influxdb/influxdb_query.py b/lib/ansible/modules/database/influxdb/influxdb_query.py\n--- a/lib/ansible/modules/database/influxdb/influxdb_query.py\n+++ b/lib/ansible/modules/database/influxdb/influxdb_query.py\n@@ -52,11 +52,11 @@\n \n - name: Print results from the query\n   debug:\n-    var: connection.results\n+    var: connection.query_results\n '''\n \n RETURN = '''\n-results:\n+query_results:\n   description: Result from the query\n   returned: success\n   type: list\n@@ -96,7 +96,7 @@\n     influx = AnsibleInfluxDBRead(module)\n     query = module.params.get('query')\n     results = influx.read_by_query(query)\n-    module.exit_json(changed=True, results=results)\n+    module.exit_json(changed=True, query_results=results)\n \n \n if __name__ == '__main__':\n", "issue": "influxdb_query fails with 'NoneType' object is not iterable\n<!---\r\nVerify first that your issue/request is not already reported on GitHub.\r\nTHIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.\r\nAlso test if the latest release, and devel branch are affected too.\r\nALWAYS add information AFTER (OUTSIDE) these html comments.\r\nOtherwise it may end up being automatically closed by our bot. -->\r\n\r\n##### SUMMARY\r\ninfluxdb_query throws an error when trying to create/drop a continuous query in influxdb using influxdb_query module but the continuous query gets created/deleted successfully nevertheless.\r\n\r\n##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### COMPONENT NAME\r\n<!--- Insert, BELOW THIS COMMENT, the name of the module, plugin, task or feature.\r\nDo not include extra details here, e.g. \"vyos_command\" not \"the network module vyos_command\" or the full path-->\r\ninfluxdb_query\r\n\r\n##### ANSIBLE VERSION\r\n<!--- Paste, BELOW THIS COMMENT, verbatim output from \"ansible --version\" between quotes below -->\r\n```\r\nansible 2.5.5\r\n  config file = /etc/ansible/ansible.cfg\r\n  configured module search path = ['/home/plamen/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']\r\n  ansible python module location = /usr/lib/python3.6/site-packages/ansible\r\n  executable location = /usr/bin/ansible\r\n  python version = 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0]\r\n```\r\n\r\n##### CONFIGURATION\r\n<!--- If using Ansible 2.4 or above, paste, BELOW THIS COMMENT, the results of \"ansible-config dump --only-changed\"\r\nOtherwise, mention any settings you have changed/added/removed in ansible.cfg\r\n(or using the ANSIBLE_* environment variables).-->\r\nDEFAULT_STDOUT_CALLBACK(/etc/ansible/ansible.cfg) = skippy\r\nRETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = False\r\n\r\n##### OS / ENVIRONMENT\r\n<!--- Mention, BELOW THIS COMMENT, the OS you are running Ansible from, and the OS you are\r\nmanaging, or say \"N/A\" for anything that is not platform-specific.\r\nAlso mention the specific version of what you are trying to control,\r\ne.g. if this is a network bug the version of firmware on the network device.-->\r\nArch Linux\r\n\r\n##### STEPS TO REPRODUCE\r\n<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.\r\nFor new features, show how the feature would be used. -->\r\n\r\n<!--- Paste example playbooks or commands between quotes below -->\r\n```yaml\r\n- name: InfluxDB | Create InfluxDB DB\r\n  influxdb_database:\r\n    database_name: \"mydb\"\r\n\r\n- name: InfluxDB | Create InfluxDB Retention Policy\r\n  influxdb_retention_policy:\r\n    database_name: \"mydb\"\r\n    policy_name: \"aggregated\"\r\n    default: no\r\n    replication: 1\r\n    duration: \"400d\"\r\n\r\n- name: InfluxDB | Create InfluxDB Continuous Query\r\n  influxdb_query:\r\n    database_name: \"mydb\"\r\n    query: \"CREATE CONTINUOUS QUERY host_router ON mydb BEGIN select sum(activeQueuedInteractions) as activeQueuedInteractions, sum(loggedUsers) as loggedUsers INTO aggregated.host_router FROM router GROUP BY hostname, time(10s, 1m) END\"\r\n```\r\nI get the same result when I try to drop the continuous query - the continuous query gets deleted but ansible fails with the same error\r\n```yaml\r\n- name: InfluxDB | Drop InfluxDB Continuous Queries\r\n  influxdb_query:\r\n    database_name: \"{{ cluster_name }}\"\r\n    query: \"DROP CONTINUOUS QUERY host_router   ON {{ cluster_name }}\"\r\n```\r\n\r\n\r\n\r\n<!--- You can also paste gist.github.com links for larger files -->\r\n\r\n##### EXPECTED RESULTS\r\nThe continuous query should be created successfully and Ansible should not fail.\r\n\r\n##### ACTUAL RESULTS\r\n<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->\r\nIt looks like influxdb_query manages to create/drop the continuous query but it throws the following error:\r\n<!--- Paste verbatim command output between quotes below -->\r\n```\r\nERROR! Unexpected Exception, this is probably a bug: 'NoneType' object is not iterable\r\nthe full traceback was:\r\n\r\nTraceback (most recent call last):\r\n  File \"/usr/bin/ansible-playbook\", line 118, in <module>\r\n    exit_code = cli.run()\r\n  File \"/usr/lib/python3.6/site-packages/ansible/cli/playbook.py\", line 122, in run\r\n    results = pbex.run()\r\n  File \"/usr/lib/python3.6/site-packages/ansible/executor/playbook_executor.py\", line 159, in run\r\n    result = self._tqm.run(play=play)\r\n  File \"/usr/lib/python3.6/site-packages/ansible/executor/task_queue_manager.py\", line 289, in run\r\n    play_return = strategy.run(iterator, play_context)\r\n  File \"/usr/lib/python3.6/site-packages/ansible/plugins/strategy/linear.py\", line 321, in run\r\n    results += self._wait_on_pending_results(iterator)\r\n  File \"/usr/lib/python3.6/site-packages/ansible/plugins/strategy/__init__.py\", line 674, in _wait_on_pending_results\r\n    results = self._process_pending_results(iterator)\r\n  File \"/usr/lib/python3.6/site-packages/ansible/plugins/strategy/__init__.py\", line 117, in inner\r\n    results = func(self, iterator, one_pass=one_pass, max_passes=max_passes)\r\n  File \"/usr/lib/python3.6/site-packages/ansible/plugins/strategy/__init__.py\", line 447, in _process_pending_results\r\n    if task_result.is_failed() or task_result.is_unreachable():\r\n  File \"/usr/lib/python3.6/site-packages/ansible/executor/task_result.py\", line 59, in is_failed\r\n    'results' in self._result and True in [True for x in self._result['results'] if 'failed_when_result' in x]:\r\nTypeError: 'NoneType' object is not iterable\r\n\r\n```\r\n\n", "before_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n# Copyright (c) 2017, Ren\u00e9 Moser <mail@renemoser.net>\n# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\n\nANSIBLE_METADATA = {'metadata_version': '1.1',\n                    'status': ['preview'],\n                    'supported_by': 'community'}\n\n\nDOCUMENTATION = '''\n---\nmodule: influxdb_query\nshort_description: Query data points from InfluxDB.\ndescription:\n  - Query data points from InfluxDB.\nversion_added: 2.5\nauthor: \"Ren\u00e9 Moser (@resmo)\"\nrequirements:\n  - \"python >= 2.6\"\n  - \"influxdb >= 0.9\"\noptions:\n  query:\n    description:\n      - Query to be executed.\n    required: true\n  database_name:\n    description:\n      - Name of the database.\n    required: true\nextends_documentation_fragment: influxdb\n'''\n\nEXAMPLES = r'''\n- name: Query connections\n  influxdb_query:\n    hostname: \"{{ influxdb_ip_address }}\"\n    database_name: \"{{ influxdb_database_name }}\"\n    query: \"select mean(value) from connections\"\n  register: connection\n\n- name: Query connections with tags filters\n  influxdb_query:\n    hostname: \"{{ influxdb_ip_address }}\"\n    database_name: \"{{ influxdb_database_name }}\"\n    query: \"select mean(value) from connections where region='zue01' and host='server01'\"\n  register: connection\n\n- name: Print results from the query\n  debug:\n    var: connection.results\n'''\n\nRETURN = '''\nresults:\n  description: Result from the query\n  returned: success\n  type: list\n  sample:\n    - mean: 1245.5333333333333\n      time: \"1970-01-01T00:00:00Z\"\n'''\n\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible.module_utils._text import to_native\nfrom ansible.module_utils.influxdb import InfluxDb\n\n\nclass AnsibleInfluxDBRead(InfluxDb):\n\n    def read_by_query(self, query):\n        client = self.connect_to_influxdb()\n        try:\n            rs = client.query(query)\n            if rs:\n                return list(rs.get_points())\n        except Exception as e:\n            self.module.fail_json(msg=to_native(e))\n\n\ndef main():\n    argument_spec = InfluxDb.influxdb_argument_spec()\n    argument_spec.update(\n        query=dict(type='str', required=True),\n        database_name=dict(required=True, type='str'),\n    )\n    module = AnsibleModule(\n        argument_spec=argument_spec,\n        supports_check_mode=True\n    )\n\n    influx = AnsibleInfluxDBRead(module)\n    query = module.params.get('query')\n    results = influx.read_by_query(query)\n    module.exit_json(changed=True, results=results)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "lib/ansible/modules/database/influxdb/influxdb_query.py"}], "after_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n# Copyright (c) 2017, Ren\u00e9 Moser <mail@renemoser.net>\n# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\n\nANSIBLE_METADATA = {'metadata_version': '1.1',\n                    'status': ['preview'],\n                    'supported_by': 'community'}\n\n\nDOCUMENTATION = '''\n---\nmodule: influxdb_query\nshort_description: Query data points from InfluxDB.\ndescription:\n  - Query data points from InfluxDB.\nversion_added: 2.5\nauthor: \"Ren\u00e9 Moser (@resmo)\"\nrequirements:\n  - \"python >= 2.6\"\n  - \"influxdb >= 0.9\"\noptions:\n  query:\n    description:\n      - Query to be executed.\n    required: true\n  database_name:\n    description:\n      - Name of the database.\n    required: true\nextends_documentation_fragment: influxdb\n'''\n\nEXAMPLES = r'''\n- name: Query connections\n  influxdb_query:\n    hostname: \"{{ influxdb_ip_address }}\"\n    database_name: \"{{ influxdb_database_name }}\"\n    query: \"select mean(value) from connections\"\n  register: connection\n\n- name: Query connections with tags filters\n  influxdb_query:\n    hostname: \"{{ influxdb_ip_address }}\"\n    database_name: \"{{ influxdb_database_name }}\"\n    query: \"select mean(value) from connections where region='zue01' and host='server01'\"\n  register: connection\n\n- name: Print results from the query\n  debug:\n    var: connection.query_results\n'''\n\nRETURN = '''\nquery_results:\n  description: Result from the query\n  returned: success\n  type: list\n  sample:\n    - mean: 1245.5333333333333\n      time: \"1970-01-01T00:00:00Z\"\n'''\n\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible.module_utils._text import to_native\nfrom ansible.module_utils.influxdb import InfluxDb\n\n\nclass AnsibleInfluxDBRead(InfluxDb):\n\n    def read_by_query(self, query):\n        client = self.connect_to_influxdb()\n        try:\n            rs = client.query(query)\n            if rs:\n                return list(rs.get_points())\n        except Exception as e:\n            self.module.fail_json(msg=to_native(e))\n\n\ndef main():\n    argument_spec = InfluxDb.influxdb_argument_spec()\n    argument_spec.update(\n        query=dict(type='str', required=True),\n        database_name=dict(required=True, type='str'),\n    )\n    module = AnsibleModule(\n        argument_spec=argument_spec,\n        supports_check_mode=True\n    )\n\n    influx = AnsibleInfluxDBRead(module)\n    query = module.params.get('query')\n    results = influx.read_by_query(query)\n    module.exit_json(changed=True, query_results=results)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "lib/ansible/modules/database/influxdb/influxdb_query.py"}]}