Skip to content

Commit

Permalink
Fix for list which raises an error
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Oct 16, 2024
1 parent 42aa14c commit 7fc87a9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
12 changes: 9 additions & 3 deletions inventree/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import json
import logging
import requests
import os

from . import api as inventree_api

INVENTREE_PYTHON_VERSION = "0.17.1"
INVENTREE_PYTHON_VERSION = "0.17.2"


logger = logging.getLogger('inventree')
Expand Down Expand Up @@ -231,10 +232,15 @@ def list(cls, api, **kwargs):
else:
url = cls.URL

response = api.get(url=url, params=kwargs)
try:
response = api.get(url=url, params=kwargs)
except requests.exceptions.HTTPError as e:
logger.error(f"Error during list request: {e}")
# Return an empty list
return []

if response is None:
return None
return []

items = []

Expand Down
28 changes: 28 additions & 0 deletions test/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,34 @@ def test_po_attachment(self):
attachments = po.getAttachments()
self.assertEqual(len(attachments), 3)

def test_invalid_list(self):
"""Test list with an invalid parameter.
Ref: https://github.com/inventree/inventree-python/issues/246
"""

from inventree.project_code import ProjectCode

results = order.PurchaseOrder.list(self.api, project_code=999999999)
self.assertEqual(len(results), 0)

# Find a valid project code
n = ProjectCode.count(self.api)

# Create a new project code
pc = ProjectCode.create(self.api, {
'code': f"TEST-{n+1}",
'description': 'Test project code',
})

# Attach project code to an order
po = order.PurchaseOrder.list(self.api, limit=1)[0]
po.save({'project_code': pc.pk})

# Now, list orders with the project code
results = order.PurchaseOrder.list(self.api, project_code=pc.pk)
self.assertEqual(len(results), 1)
self.assertEqual(results[0].pk, po.pk)

class SOTest(InvenTreeTestCase):
"""
Expand Down

0 comments on commit 7fc87a9

Please sign in to comment.