From c7bcc25a361f9df440f9c972672e5eec3b057625 Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Mon, 31 May 2021 10:47:03 -0700 Subject: fix: catch invalid type used to initialize RESTObject Sometimes we have errors where we don't get a dictionary passed to RESTObject.__init__() method. This breaks things but in confusing ways. Check in the __init__() method and raise an exception if it occurs. --- gitlab/base.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gitlab/base.py') diff --git a/gitlab/base.py b/gitlab/base.py index 689b68c..bea1901 100644 --- a/gitlab/base.py +++ b/gitlab/base.py @@ -20,6 +20,7 @@ from types import ModuleType from typing import Any, Dict, Iterable, NamedTuple, Optional, Tuple, Type from gitlab import types as g_types +from gitlab.exceptions import GitlabParsingError from .client import Gitlab, GitlabList @@ -51,6 +52,12 @@ class RESTObject(object): manager: "RESTManager" def __init__(self, manager: "RESTManager", attrs: Dict[str, Any]) -> None: + if not isinstance(attrs, dict): + raise GitlabParsingError( + "Attempted to initialize RESTObject with a non-dictionary value: " + "{!r}\nThis likely indicates an incorrect or malformed server " + "response.".format(attrs) + ) self.__dict__.update( { "manager": manager, -- cgit v1.2.1