Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

IndexError when printing dashboard response containing empty group_by list

Offen
#3,656 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
75/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Ruhig
Tech-Stack
python
Bereich
api, tooling

Rechercherichtung

Beginne in .generator/src/generator/templates/model_utils.j2 und konzentriere dich auf model_to_dict() und get_oneof_instance(), die src/datadog_api_client/model_utils.py generieren. Reproduziere den Fall eines leeren group_by über DashboardsApi.get_dashboard() und gib print(response) oder to_dict() aus. Die Aufgabe ist erledigt, wenn die response serialisiert und ohne IndexError ausgegeben wird, wenn _composed_instances leer ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

kind/bug stale

Describe the bug
Calling print(response) on a dashboard response raises IndexError: list index out of range when the dashboard contains a query_value widget with a logs query that has "group_by": [] (empty list).

Labels: kind/bug, severity/major

To Reproduce

  1. Create a dashboard with a query_value widget using a logs query with group_by set to an empty list.
  2. Call get_dashboard() using the Python API client.
  3. Call print(response) on the returned object.
  4. See IndexError: list index out of range.

Minimal reproduction:

from datadog_api_client import Configuration, ApiClient
from datadog_api_client.v1.api.dashboards_api import DashboardsApi

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api = DashboardsApi(api_client)
    response = api.get_dashboard(dashboard_id="<dashboard-id>")
    print(response)  # raises IndexError

Expected behavior
The response should be printed (or serialized via to_dict()) without raising any exception.

Screenshots

Image
Traceback (most recent call last):
  File "main.py", line 8, in <module>
    print(response)
  File ".venv/lib/python3.14/site-packages/datadog_api_client/model_utils.py", line 194, in __repr__
    return self.to_str()
  File ".venv/lib/python3.14/site-packages/datadog_api_client/model_utils.py", line 422, in to_str
    return pprint.pformat(self.to_dict())
  File ".venv/lib/python3.14/site-packages/datadog_api_client/model_utils.py", line 418, in to_dict
    return model_to_dict(self, serialize=False)
  File ".venv/lib/python3.14/site-packages/datadog_api_client/model_utils.py", line 1502, in model_to_dict
    model = model.get_oneof_instance()
  File ".venv/lib/python3.14/site-packages/datadog_api_client/model_utils.py", line 581, in get_oneof_instance
    return self._composed_instances[0]
IndexError: list index out of range

Root cause
group_by is typed as FormulaAndFunctionEventQueryGroupByConfig, a ModelComposed class with a oneOf of two variants: a list of group-by objects and a fields object. When the API returns "group_by": [], the oneOf matcher cannot determine which variant the empty list belongs to, so _composed_instances is left empty.

model_to_dict() in model_utils.py enters its traversal loop based on _composed_schemas being non-empty, without checking whether _composed_instances is populated, and then crashes at get_oneof_instance() which unconditionally accesses self._composed_instances[0].

Workaround
Set configuration.preload_content = False to skip deserialization and parse the raw JSON manually:

import json
from datadog_api_client import Configuration, ApiClient
from datadog_api_client.v1.api.dashboards_api import DashboardsApi

configuration = Configuration()
configuration.preload_content = False
with ApiClient(configuration) as api_client:
    api = DashboardsApi(api_client)
    response = api.get_dashboard(dashboard_id="<dashboard-id>")
    data = json.loads(response.data)
    print(json.dumps(data, indent=2))

Environment and Versions (please complete the following information):

  • datadog-api-client version: 2.55.0 (latest)
  • Python version: 3.14
  • OS: macOS

Additional context
The fix requires two changes in .generator/src/generator/templates/model_utils.j2 (the template that generates src/datadog_api_client/model_utils.py):

  1. Guard the loop in model_to_dict() to only enter when _composed_instances is also non-empty:

    while model._composed_schemas and model._composed_instances:
    
  2. Make get_oneof_instance() fall back to self instead of crashing when _composed_instances is empty:

    def get_oneof_instance(self):
        if not self._composed_instances:
            return self
        return self._composed_instances[0]
    
Vorherrschende Sprache
Python
Sterne
167
Forks
55
Ø Merge
3 T. 17 Std.
Gemergte PRs (30 T.)
80

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus DataDog/datadog-api-client-python

Alle Issues in DataDog/datadog-api-client-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.