# Buggy code
def query_obj(self):
    form_data = self.form_data
    d = super().query_obj()
    d["groupby"] = [
        form_data.get("entity"),
    ]
    if form_data.get("series"):
        d["groupby"].append(form_data.get("series"))
    self.x_metric = form_data.get("x")
    self.y_metric = form_data.get("y")
    self.z_metric = form_data.get("size")
    self.entity = form_data.get("entity")
    self.series = form_data.get("series") or self.entity
    d["row_limit"] = form_data.get("limit")

    d["metrics"] = [
        self.z_metric,
        self.x_metric,
        self.y_metric,
    ]
    if not all(d["metrics"] + [self.entity]):
        raise Exception(_("Pick a metric for x, y and size"))
    return d


# Traceback (KeyError)
Traceback (most recent call last):
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 3078, in get_loc
return self._engine.get_loc(key)
File "pandas/_libs/index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 157, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 183, in pandas._libs.index.IndexEngine._get_loc_duplicates
File "pandas/_libs/index.pyx", line 200, in pandas._libs.index.IndexEngine._maybe_get_bool_indexer
KeyError: 'x'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/internals.py", line 4243, in set
loc = self.items.get_loc(item)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 3080, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/_libs/index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 157, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 183, in pandas._libs.index.IndexEngine._get_loc_duplicates
File "pandas/_libs/index.pyx", line 200, in pandas._libs.index.IndexEngine._maybe_get_bool_indexer
KeyError: 'x'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/views/base.py", line 114, in wraps
return f(self, *args, **kwargs)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/views/core.py", line 1229, in explore_json
samples=samples,
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/views/core.py", line 1160, in generate_json
payload = viz_obj.get_payload()
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/viz.py", line 375, in get_payload
payload['data'] = self.get_data(df)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/viz.py", line 967, in get_data
df['x'] = df[[utils.get_metric_name(self.x_metric)]]
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/frame.py", line 3119, in __setitem__
self._set_item(key, value)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/frame.py", line 3195, in _set_item
NDFrame._set_item(self, key, value)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/generic.py", line 2600, in _set_item
self._data.set(key, value)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/internals.py", line 4246, in set
self.insert(len(self.items), item, value)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/internals.py", line 4347, in insert
placement=slice(loc, loc + 1))
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/internals.py", line 3205, in make_block
return klass(values, ndim=ndim, placement=placement)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/pandas/core/internals.py", line 125, in __init__
'{mgr}'.format(val=len(self.values), mgr=len(self.mgr_locs)))
ValueError: Wrong number of items passed 2, placement implies 1

# Fixed code
def query_obj(self):
    form_data = self.form_data
    d = super().query_obj()
    d["groupby"] = [
        form_data.get("entity"),
    ]
    if form_data.get("series"):
        d["groupby"].append(form_data.get("series"))
    self.x_metric = form_data.get("x")
    self.y_metric = form_data.get("y")
    self.z_metric = form_data.get("size")
    self.entity = form_data.get("entity")
    self.series = form_data.get("series") or self.entity
    d["row_limit"] = form_data.get("limit")

    d["metrics"] = list(
        set(
            [
                self.z_metric,
                self.x_metric,
                self.y_metric,
            ]
        )
    )
    if not all(d["metrics"] + [self.entity]):
        raise Exception(_("Pick a metric for x, y and size"))
    return d