Skip to content

Commit 7fc87a9

Browse files
Fix for list which raises an error
1 parent 42aa14c commit 7fc87a9

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

inventree/base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import json
44
import logging
5+
import requests
56
import os
67

78
from . import api as inventree_api
89

9-
INVENTREE_PYTHON_VERSION = "0.17.1"
10+
INVENTREE_PYTHON_VERSION = "0.17.2"
1011

1112

1213
logger = logging.getLogger('inventree')
@@ -231,10 +232,15 @@ def list(cls, api, **kwargs):
231232
else:
232233
url = cls.URL
233234

234-
response = api.get(url=url, params=kwargs)
235+
try:
236+
response = api.get(url=url, params=kwargs)
237+
except requests.exceptions.HTTPError as e:
238+
logger.error(f"Error during list request: {e}")
239+
# Return an empty list
240+
return []
235241

236242
if response is None:
237-
return None
243+
return []
238244

239245
items = []
240246

test/test_order.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,34 @@ def test_po_attachment(self):
390390
attachments = po.getAttachments()
391391
self.assertEqual(len(attachments), 3)
392392

393+
def test_invalid_list(self):
394+
"""Test list with an invalid parameter.
395+
396+
Ref: https://github.com/inventree/inventree-python/issues/246
397+
"""
398+
399+
from inventree.project_code import ProjectCode
400+
401+
results = order.PurchaseOrder.list(self.api, project_code=999999999)
402+
self.assertEqual(len(results), 0)
403+
404+
# Find a valid project code
405+
n = ProjectCode.count(self.api)
406+
407+
# Create a new project code
408+
pc = ProjectCode.create(self.api, {
409+
'code': f"TEST-{n+1}",
410+
'description': 'Test project code',
411+
})
412+
413+
# Attach project code to an order
414+
po = order.PurchaseOrder.list(self.api, limit=1)[0]
415+
po.save({'project_code': pc.pk})
416+
417+
# Now, list orders with the project code
418+
results = order.PurchaseOrder.list(self.api, project_code=pc.pk)
419+
self.assertEqual(len(results), 1)
420+
self.assertEqual(results[0].pk, po.pk)
393421

394422
class SOTest(InvenTreeTestCase):
395423
"""

0 commit comments

Comments
 (0)