From 6ef81e9807ce88881ac003168e49a415b75c9522 Mon Sep 17 00:00:00 2001 From: Kristi Nikolla Date: Wed, 1 May 2024 10:20:33 -0400 Subject: [PATCH] Handle TypeError in Pci Requests Closes https://github.com/CCI-MOC/openstack-billing-from-db/issues/59 --- src/openstack_billing_db/model.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/openstack_billing_db/model.py b/src/openstack_billing_db/model.py index 2cb003c..8b9cc21 100644 --- a/src/openstack_billing_db/model.py +++ b/src/openstack_billing_db/model.py @@ -3,9 +3,12 @@ import datetime from dataclasses import dataclass from dataclasses_json import dataclass_json +import logging import sqlite3 from typing import Optional +logger = logging.getLogger(__name__) + @dataclass_json() @dataclass() @@ -230,7 +233,13 @@ def get_instances(self, project) -> list[Instance]: ) for instance in cursor.fetchall(): - pci_info = json.loads(instance["pci_requests"]) + try: + pci_info = json.loads(instance["pci_requests"]) + except TypeError: + pci_info = None + logger.warning( + f"Could not parse pci requests from instance {instance}." + ) su_name = "cpu" if pci_info: # The PCI Requests column of the database contains a JSON