Duplicate legend entries / frames when using query.lookback-delta or last_over_time

I’m using Prometheus and Grafana (the latest docker images) to store data from my home IoT setup. Because it’s IoT, the data points come in somewhat sporadically and thats expected. To combat that I’ve used both last_over_time from PromQL and also changing the --query.lookback-delta command line parameter for Prometheus, but the results are the same.

When I create a graph in a dashboard (it doesn’t happen in Explore) I get multiple entries in the legend for the same thing. As you can see from the chart, it’s basically the chart I’d expect, along with a single value that’s the present value that’s separate. I’ve tried to dig into it a little and I think it’s caused by the fact that there are two entries frames in the query response. I’m not totally sure whether the values in the response object are directly from Prometheus or already parsed by Grafana, so I’m not totally sure where the breakdown is, but it confirms the theory that there’s just one data point at the end for some reason.

Here’s what I’m seeing, with the duplicates:

Here is the Query Inspector:

{
  "request": {
    "url": "api/ds/query",
    "method": "POST",
    "data": {
      "queries": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "kqCSiapVz"
          },
          "editorMode": "builder",
          "exemplar": false,
          "expr": "temperature{sensor=~\"basement\"}",
          "hide": false,
          "instant": true,
          "key": "Q-c72a8c45-99db-4242-b3da-e071d2656b2c-1",
          "legendFormat": "Basement",
          "range": true,
          "refId": "B",
          "queryType": "timeSeriesQuery",
          "requestId": "5B",
          "utcOffsetSec": -28800,
          "interval": "",
          "datasourceId": 1,
          "intervalMs": 15000,
          "maxDataPoints": 1008
        }
      ],
      "range": {
        "from": "2023-01-13T01:44:52.531Z",
        "to": "2023-01-13T02:44:52.531Z",
        "raw": {
          "from": "now-1h",
          "to": "now"
        }
      },
      "from": "1673574292531",
      "to": "1673577892531"
    },
    "hideFromInspector": false
  },
  "response": {
    "results": {
      "B": {
        "status": 200,
        "frames": [
          {
            "schema": {
              "name": "Basement",
              "refId": "B",
              "meta": {
                "type": "timeseries-many",
                "custom": {
                  "resultType": "vector"
                },
                "executedQueryString": "Expr: temperature{sensor=~\"basement\"}\nStep: 15s"
              },
              "fields": [
                {
                  "name": "Time",
                  "type": "time",
                  "typeInfo": {
                    "frame": "time.Time"
                  },
                  "config": {
                    "interval": 15000
                  }
                },
                {
                  "name": "Value",
                  "type": "number",
                  "typeInfo": {
                    "frame": "float64"
                  },
                  "labels": {
                    "__name__": "temperature",
                    "instance": "localhost:9641",
                    "job": "mqtt2prometheus",
                    "sensor": "basement",
                    "topic": "zigbee2mqtt/basement"
                  },
                  "config": {
                    "displayNameFromDS": "Basement"
                  }
                }
              ]
            },
            "data": {
              "values": [
                [
                  1673577885000
                ],
                [
                  19.68
                ]
              ]
            }
          },
          {
            "schema": {
              "name": "Basement",
              "refId": "B",
              "meta": {
                "type": "timeseries-many",
                "custom": {
                  "resultType": "matrix"
                },
                "executedQueryString": "Expr: temperature{sensor=~\"basement\"}\nStep: 15s"
              },
              "fields": [
                {
                  "name": "Time",
                  "type": "time",
                  "typeInfo": {
                    "frame": "time.Time"
                  },
                  "config": {
                    "interval": 15000
                  }
                },
                {
                  "name": "Value",
                  "type": "number",
                  "typeInfo": {
                    "frame": "float64"
                  },
                  "labels": {
                    "__name__": "temperature",
                    "instance": "localhost:9641",
                    "job": "mqtt2prometheus",
                    "sensor": "basement",
                    "topic": "zigbee2mqtt/basement"
                  },
                  "config": {
                    "displayNameFromDS": "Basement"
                  }
                }
              ]
            },
            "data": {
              "values": [
                [
                  1673574285000,
                  1673574300000,
                   ....<many more values>...
                ],
                [
                  19.69,
                  19.69,
                   ....<many more values>...
                ]
              ]
            }
          }
        ],
        "refId": "B"
      }
    }
  }
}