We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[AKS] az aks get-upgrades --output table fails on extensions
- If the issue is to do with Azure CLI 2.0 in-particular, create an issue here at [Azure/azure-cli](https://github.com/Azure/azure-cli/issues)

### Extension name (the extension in question)
aks-preview

### Description of issue (in as much detail as possible)
Running
```
az aks get-upgrades -g {{RG_NAME}} -n {{CLUSTER_NAME}} --output table
```
fails with

```
preview/azext_aks_preview/_format.py", line 72, in aks_upgrades_table_format
    find_preview_versions(result.get('agentPoolProfiles', [{}])[0])
TypeError: 'NoneType' object is not subscriptable

cli.azure.cli.core.util : Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.
Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.
```

The fix is to not use the agentPoolProfile when formatting the table since the field is nil. We need to update the formatter.

Issue is only when using extensions and the -o table. Works fine on CLI core.
-----



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/aks-preview/azext_aks_preview/_format.py`
Content:
```
1 # --------------------------------------------------------------------------------------------
2 # Copyright (c) Microsoft Corporation. All rights reserved.
3 # Licensed under the MIT License. See License.txt in the project root for license information.
4 # --------------------------------------------------------------------------------------------
5 
6 from collections import OrderedDict
7 # pylint: disable=import-error
8 from jmespath import compile as compile_jmes, Options
9 # pylint: disable=import-error
10 from jmespath import functions
11 
12 
13 def aks_agentpool_show_table_format(result):
14     """Format an agent pool as summary results for display with "-o table"."""
15     return [_aks_agentpool_table_format(result)]
16 
17 
18 def _aks_agentpool_table_format(result):
19     parsed = compile_jmes("""{
20         name: name,
21         osType: osType,
22         kubernetesVersion: kubernetesVersion,
23         vmSize: vmSize,
24         osDiskSizeGB: osDiskSizeGB,
25         count: count,
26         maxPods: maxPods,
27         provisioningState: provisioningState,
28         mode: mode
29     }""")
30     # use ordered dicts so headers are predictable
31     return parsed.search(result, Options(dict_cls=OrderedDict))
32 
33 
34 def aks_agentpool_list_table_format(results):
35     """Format an agent pool list for display with "-o table"."""
36     return [_aks_agentpool_table_format(r) for r in results]
37 
38 
39 def aks_list_table_format(results):
40     """"Format a list of managed clusters as summary results for display with "-o table"."""
41     return [_aks_table_format(r) for r in results]
42 
43 
44 def aks_show_table_format(result):
45     """Format a managed cluster as summary results for display with "-o table"."""
46     return [_aks_table_format(result)]
47 
48 
49 def _aks_table_format(result):
50     parsed = compile_jmes("""{
51         name: name,
52         location: location,
53         resourceGroup: resourceGroup,
54         kubernetesVersion: kubernetesVersion,
55         provisioningState: provisioningState,
56         fqdn: fqdn
57     }""")
58     # use ordered dicts so headers are predictable
59     return parsed.search(result, Options(dict_cls=OrderedDict))
60 
61 
62 def aks_upgrades_table_format(result):
63     """Format get-upgrades results as a summary for display with "-o table"."""
64 
65     preview = {}
66 
67     def find_preview_versions(versions_bag):
68         for upgrade in versions_bag.get('upgrades', []):
69             if upgrade.get('isPreview', False):
70                 preview[upgrade['kubernetesVersion']] = True
71     find_preview_versions(result.get('controlPlaneProfile', {}))
72     find_preview_versions(result.get('agentPoolProfiles', [{}])[0])
73 
74     # This expression assumes there is one node pool, and that the master and nodes upgrade in lockstep.
75     parsed = compile_jmes("""{
76         name: name,
77         resourceGroup: resourceGroup,
78         masterVersion: controlPlaneProfile.kubernetesVersion || `unknown` | set_preview(@),
79         nodePoolVersion: agentPoolProfiles[0].kubernetesVersion || `unknown` | set_preview(@),
80         upgrades: controlPlaneProfile.upgrades[].kubernetesVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)
81     }""")
82     # use ordered dicts so headers are predictable
83     return parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))
84 
85 
86 def aks_versions_table_format(result):
87     """Format get-versions results as a summary for display with "-o table"."""
88 
89     # get preview orchestrator version
90     preview = {}
91 
92     def find_preview_versions():
93         for orchestrator in result.get('orchestrators', []):
94             if orchestrator.get('isPreview', False):
95                 preview[orchestrator['orchestratorVersion']] = True
96     find_preview_versions()
97 
98     parsed = compile_jmes("""orchestrators[].{
99         kubernetesVersion: orchestratorVersion | set_preview(@),
100         upgrades: upgrades[].orchestratorVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)
101     }""")
102     # use ordered dicts so headers are predictable
103     results = parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))
104     return sorted(results, key=lambda x: version_to_tuple(x.get('kubernetesVersion')), reverse=True)
105 
106 
107 def version_to_tuple(version):
108     """Removes preview suffix"""
109     if version.endswith('(preview)'):
110         version = version[:-len('(preview)')]
111     return tuple(map(int, (version.split('.'))))
112 
113 
114 def _custom_functions(preview_versions):
115     class CustomFunctions(functions.Functions):  # pylint: disable=too-few-public-methods
116 
117         @functions.signature({'types': ['array']})
118         def _func_sort_versions(self, versions):  # pylint: disable=no-self-use
119             """Custom JMESPath `sort_versions` function that sorts an array of strings as software versions"""
120             try:
121                 return sorted(versions, key=version_to_tuple)
122             except (TypeError, ValueError):  # if it wasn't sortable, return the input so the pipeline continues
123                 return versions
124 
125         @functions.signature({'types': ['array']})
126         def _func_set_preview_array(self, versions):
127             """Custom JMESPath `set_preview_array` function that suffixes preview version"""
128             try:
129                 for i, _ in enumerate(versions):
130                     versions[i] = self._func_set_preview(versions[i])
131                 return versions
132             except(TypeError, ValueError):
133                 return versions
134 
135         @functions.signature({'types': ['string']})
136         def _func_set_preview(self, version):  # pylint: disable=no-self-use
137             """Custom JMESPath `set_preview` function that suffixes preview version"""
138             try:
139                 if preview_versions.get(version, False):
140                     return version + '(preview)'
141                 return version
142             except(TypeError, ValueError):
143                 return version
144 
145     return CustomFunctions()
146
```
--- 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/src/aks-preview/azext_aks_preview/_format.py b/src/aks-preview/azext_aks_preview/_format.py
--- a/src/aks-preview/azext_aks_preview/_format.py
+++ b/src/aks-preview/azext_aks_preview/_format.py
@@ -69,14 +69,12 @@
             if upgrade.get('isPreview', False):
                 preview[upgrade['kubernetesVersion']] = True
     find_preview_versions(result.get('controlPlaneProfile', {}))
-    find_preview_versions(result.get('agentPoolProfiles', [{}])[0])
 
     # This expression assumes there is one node pool, and that the master and nodes upgrade in lockstep.
     parsed = compile_jmes("""{
         name: name,
         resourceGroup: resourceGroup,
-        masterVersion: controlPlaneProfile.kubernetesVersion || `unknown` | set_preview(@),
-        nodePoolVersion: agentPoolProfiles[0].kubernetesVersion || `unknown` | set_preview(@),
+        masterVersion: controlPlaneProfile.kubernetesVersion || `unknown`,
         upgrades: controlPlaneProfile.upgrades[].kubernetesVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)
     }""")
     # use ordered dicts so headers are predictable

{"golden_diff": "diff --git a/src/aks-preview/azext_aks_preview/_format.py b/src/aks-preview/azext_aks_preview/_format.py\n--- a/src/aks-preview/azext_aks_preview/_format.py\n+++ b/src/aks-preview/azext_aks_preview/_format.py\n@@ -69,14 +69,12 @@\n             if upgrade.get('isPreview', False):\n                 preview[upgrade['kubernetesVersion']] = True\n     find_preview_versions(result.get('controlPlaneProfile', {}))\n-    find_preview_versions(result.get('agentPoolProfiles', [{}])[0])\n \n     # This expression assumes there is one node pool, and that the master and nodes upgrade in lockstep.\n     parsed = compile_jmes(\"\"\"{\n         name: name,\n         resourceGroup: resourceGroup,\n-        masterVersion: controlPlaneProfile.kubernetesVersion || `unknown` | set_preview(@),\n-        nodePoolVersion: agentPoolProfiles[0].kubernetesVersion || `unknown` | set_preview(@),\n+        masterVersion: controlPlaneProfile.kubernetesVersion || `unknown`,\n         upgrades: controlPlaneProfile.upgrades[].kubernetesVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)\n     }\"\"\")\n     # use ordered dicts so headers are predictable\n", "issue": "[AKS] az aks get-upgrades --output table fails on extensions\n- If the issue is to do with Azure CLI 2.0 in-particular, create an issue here at [Azure/azure-cli](https://github.com/Azure/azure-cli/issues)\r\n\r\n### Extension name (the extension in question)\r\naks-preview\r\n\r\n### Description of issue (in as much detail as possible)\r\nRunning\r\n```\r\naz aks get-upgrades -g {{RG_NAME}} -n {{CLUSTER_NAME}} --output table\r\n```\r\nfails with\r\n\r\n```\r\npreview/azext_aks_preview/_format.py\", line 72, in aks_upgrades_table_format\r\n    find_preview_versions(result.get('agentPoolProfiles', [{}])[0])\r\nTypeError: 'NoneType' object is not subscriptable\r\n\r\ncli.azure.cli.core.util : Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.\r\nTable output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.\r\n```\r\n\r\nThe fix is to not use the agentPoolProfile when formatting the table since the field is nil. We need to update the formatter.\r\n\r\nIssue is only when using extensions and the -o table. Works fine on CLI core.\r\n-----\r\n\r\n\n", "before_files": [{"content": "# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nfrom collections import OrderedDict\n# pylint: disable=import-error\nfrom jmespath import compile as compile_jmes, Options\n# pylint: disable=import-error\nfrom jmespath import functions\n\n\ndef aks_agentpool_show_table_format(result):\n    \"\"\"Format an agent pool as summary results for display with \"-o table\".\"\"\"\n    return [_aks_agentpool_table_format(result)]\n\n\ndef _aks_agentpool_table_format(result):\n    parsed = compile_jmes(\"\"\"{\n        name: name,\n        osType: osType,\n        kubernetesVersion: kubernetesVersion,\n        vmSize: vmSize,\n        osDiskSizeGB: osDiskSizeGB,\n        count: count,\n        maxPods: maxPods,\n        provisioningState: provisioningState,\n        mode: mode\n    }\"\"\")\n    # use ordered dicts so headers are predictable\n    return parsed.search(result, Options(dict_cls=OrderedDict))\n\n\ndef aks_agentpool_list_table_format(results):\n    \"\"\"Format an agent pool list for display with \"-o table\".\"\"\"\n    return [_aks_agentpool_table_format(r) for r in results]\n\n\ndef aks_list_table_format(results):\n    \"\"\"\"Format a list of managed clusters as summary results for display with \"-o table\".\"\"\"\n    return [_aks_table_format(r) for r in results]\n\n\ndef aks_show_table_format(result):\n    \"\"\"Format a managed cluster as summary results for display with \"-o table\".\"\"\"\n    return [_aks_table_format(result)]\n\n\ndef _aks_table_format(result):\n    parsed = compile_jmes(\"\"\"{\n        name: name,\n        location: location,\n        resourceGroup: resourceGroup,\n        kubernetesVersion: kubernetesVersion,\n        provisioningState: provisioningState,\n        fqdn: fqdn\n    }\"\"\")\n    # use ordered dicts so headers are predictable\n    return parsed.search(result, Options(dict_cls=OrderedDict))\n\n\ndef aks_upgrades_table_format(result):\n    \"\"\"Format get-upgrades results as a summary for display with \"-o table\".\"\"\"\n\n    preview = {}\n\n    def find_preview_versions(versions_bag):\n        for upgrade in versions_bag.get('upgrades', []):\n            if upgrade.get('isPreview', False):\n                preview[upgrade['kubernetesVersion']] = True\n    find_preview_versions(result.get('controlPlaneProfile', {}))\n    find_preview_versions(result.get('agentPoolProfiles', [{}])[0])\n\n    # This expression assumes there is one node pool, and that the master and nodes upgrade in lockstep.\n    parsed = compile_jmes(\"\"\"{\n        name: name,\n        resourceGroup: resourceGroup,\n        masterVersion: controlPlaneProfile.kubernetesVersion || `unknown` | set_preview(@),\n        nodePoolVersion: agentPoolProfiles[0].kubernetesVersion || `unknown` | set_preview(@),\n        upgrades: controlPlaneProfile.upgrades[].kubernetesVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)\n    }\"\"\")\n    # use ordered dicts so headers are predictable\n    return parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))\n\n\ndef aks_versions_table_format(result):\n    \"\"\"Format get-versions results as a summary for display with \"-o table\".\"\"\"\n\n    # get preview orchestrator version\n    preview = {}\n\n    def find_preview_versions():\n        for orchestrator in result.get('orchestrators', []):\n            if orchestrator.get('isPreview', False):\n                preview[orchestrator['orchestratorVersion']] = True\n    find_preview_versions()\n\n    parsed = compile_jmes(\"\"\"orchestrators[].{\n        kubernetesVersion: orchestratorVersion | set_preview(@),\n        upgrades: upgrades[].orchestratorVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)\n    }\"\"\")\n    # use ordered dicts so headers are predictable\n    results = parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))\n    return sorted(results, key=lambda x: version_to_tuple(x.get('kubernetesVersion')), reverse=True)\n\n\ndef version_to_tuple(version):\n    \"\"\"Removes preview suffix\"\"\"\n    if version.endswith('(preview)'):\n        version = version[:-len('(preview)')]\n    return tuple(map(int, (version.split('.'))))\n\n\ndef _custom_functions(preview_versions):\n    class CustomFunctions(functions.Functions):  # pylint: disable=too-few-public-methods\n\n        @functions.signature({'types': ['array']})\n        def _func_sort_versions(self, versions):  # pylint: disable=no-self-use\n            \"\"\"Custom JMESPath `sort_versions` function that sorts an array of strings as software versions\"\"\"\n            try:\n                return sorted(versions, key=version_to_tuple)\n            except (TypeError, ValueError):  # if it wasn't sortable, return the input so the pipeline continues\n                return versions\n\n        @functions.signature({'types': ['array']})\n        def _func_set_preview_array(self, versions):\n            \"\"\"Custom JMESPath `set_preview_array` function that suffixes preview version\"\"\"\n            try:\n                for i, _ in enumerate(versions):\n                    versions[i] = self._func_set_preview(versions[i])\n                return versions\n            except(TypeError, ValueError):\n                return versions\n\n        @functions.signature({'types': ['string']})\n        def _func_set_preview(self, version):  # pylint: disable=no-self-use\n            \"\"\"Custom JMESPath `set_preview` function that suffixes preview version\"\"\"\n            try:\n                if preview_versions.get(version, False):\n                    return version + '(preview)'\n                return version\n            except(TypeError, ValueError):\n                return version\n\n    return CustomFunctions()\n", "path": "src/aks-preview/azext_aks_preview/_format.py"}], "after_files": [{"content": "# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nfrom collections import OrderedDict\n# pylint: disable=import-error\nfrom jmespath import compile as compile_jmes, Options\n# pylint: disable=import-error\nfrom jmespath import functions\n\n\ndef aks_agentpool_show_table_format(result):\n    \"\"\"Format an agent pool as summary results for display with \"-o table\".\"\"\"\n    return [_aks_agentpool_table_format(result)]\n\n\ndef _aks_agentpool_table_format(result):\n    parsed = compile_jmes(\"\"\"{\n        name: name,\n        osType: osType,\n        kubernetesVersion: kubernetesVersion,\n        vmSize: vmSize,\n        osDiskSizeGB: osDiskSizeGB,\n        count: count,\n        maxPods: maxPods,\n        provisioningState: provisioningState,\n        mode: mode\n    }\"\"\")\n    # use ordered dicts so headers are predictable\n    return parsed.search(result, Options(dict_cls=OrderedDict))\n\n\ndef aks_agentpool_list_table_format(results):\n    \"\"\"Format an agent pool list for display with \"-o table\".\"\"\"\n    return [_aks_agentpool_table_format(r) for r in results]\n\n\ndef aks_list_table_format(results):\n    \"\"\"\"Format a list of managed clusters as summary results for display with \"-o table\".\"\"\"\n    return [_aks_table_format(r) for r in results]\n\n\ndef aks_show_table_format(result):\n    \"\"\"Format a managed cluster as summary results for display with \"-o table\".\"\"\"\n    return [_aks_table_format(result)]\n\n\ndef _aks_table_format(result):\n    parsed = compile_jmes(\"\"\"{\n        name: name,\n        location: location,\n        resourceGroup: resourceGroup,\n        kubernetesVersion: kubernetesVersion,\n        provisioningState: provisioningState,\n        fqdn: fqdn\n    }\"\"\")\n    # use ordered dicts so headers are predictable\n    return parsed.search(result, Options(dict_cls=OrderedDict))\n\n\ndef aks_upgrades_table_format(result):\n    \"\"\"Format get-upgrades results as a summary for display with \"-o table\".\"\"\"\n\n    preview = {}\n\n    def find_preview_versions(versions_bag):\n        for upgrade in versions_bag.get('upgrades', []):\n            if upgrade.get('isPreview', False):\n                preview[upgrade['kubernetesVersion']] = True\n    find_preview_versions(result.get('controlPlaneProfile', {}))\n\n    # This expression assumes there is one node pool, and that the master and nodes upgrade in lockstep.\n    parsed = compile_jmes(\"\"\"{\n        name: name,\n        resourceGroup: resourceGroup,\n        masterVersion: controlPlaneProfile.kubernetesVersion || `unknown`,\n        upgrades: controlPlaneProfile.upgrades[].kubernetesVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)\n    }\"\"\")\n    # use ordered dicts so headers are predictable\n    return parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))\n\n\ndef aks_versions_table_format(result):\n    \"\"\"Format get-versions results as a summary for display with \"-o table\".\"\"\"\n\n    # get preview orchestrator version\n    preview = {}\n\n    def find_preview_versions():\n        for orchestrator in result.get('orchestrators', []):\n            if orchestrator.get('isPreview', False):\n                preview[orchestrator['orchestratorVersion']] = True\n    find_preview_versions()\n\n    parsed = compile_jmes(\"\"\"orchestrators[].{\n        kubernetesVersion: orchestratorVersion | set_preview(@),\n        upgrades: upgrades[].orchestratorVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)\n    }\"\"\")\n    # use ordered dicts so headers are predictable\n    results = parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))\n    return sorted(results, key=lambda x: version_to_tuple(x.get('kubernetesVersion')), reverse=True)\n\n\ndef version_to_tuple(version):\n    \"\"\"Removes preview suffix\"\"\"\n    if version.endswith('(preview)'):\n        version = version[:-len('(preview)')]\n    return tuple(map(int, (version.split('.'))))\n\n\ndef _custom_functions(preview_versions):\n    class CustomFunctions(functions.Functions):  # pylint: disable=too-few-public-methods\n\n        @functions.signature({'types': ['array']})\n        def _func_sort_versions(self, versions):  # pylint: disable=no-self-use\n            \"\"\"Custom JMESPath `sort_versions` function that sorts an array of strings as software versions\"\"\"\n            try:\n                return sorted(versions, key=version_to_tuple)\n            except (TypeError, ValueError):  # if it wasn't sortable, return the input so the pipeline continues\n                return versions\n\n        @functions.signature({'types': ['array']})\n        def _func_set_preview_array(self, versions):\n            \"\"\"Custom JMESPath `set_preview_array` function that suffixes preview version\"\"\"\n            try:\n                for i, _ in enumerate(versions):\n                    versions[i] = self._func_set_preview(versions[i])\n                return versions\n            except(TypeError, ValueError):\n                return versions\n\n        @functions.signature({'types': ['string']})\n        def _func_set_preview(self, version):  # pylint: disable=no-self-use\n            \"\"\"Custom JMESPath `set_preview` function that suffixes preview version\"\"\"\n            try:\n                if preview_versions.get(version, False):\n                    return version + '(preview)'\n                return version\n            except(TypeError, ValueError):\n                return version\n\n    return CustomFunctions()\n", "path": "src/aks-preview/azext_aks_preview/_format.py"}]}