Skip to content

Commit

Permalink
re-raise validation exception
Browse files Browse the repository at this point in the history
  • Loading branch information
FabriciaDinizRH committed Jan 13, 2025
1 parent 507b74e commit 5403b89
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions api/filtering/db_custom_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,27 @@
# The list of comparators can be seen in POSTGRES_COMPARATOR_LOOKUP
class OsFilter:
def __init__(self, name="", comparator="", version=None):
if name and name.lower() not in (os_names := [name.lower() for name in get_valid_os_names()]):
raise ValidationException(f"operating_system filter only supports these OS names: {os_names}.")
try:
if name and name.lower() not in (os_names := [name.lower() for name in get_valid_os_names()]):
raise ValidationException(f"operating_system filter only supports these OS names: {os_names}.")

if version is None:
major, minor = None, None
else:
version_split = version.split(".")

if len(version_split) > 2:
raise ValidationException("operating_system filter can only have a major and minor version.")
elif len(version_split) == 1: # only major version was sent
major = version_split[0]
minor = None
if version is None:
major, minor = None, None
else:
major, minor = version_split

if not major.isdigit() or (minor and not minor.isdigit()):
raise ValidationException("operating_system major and minor versions must be numerical.")
version_split = version.split(".")

if len(version_split) > 2:
raise ValidationException("operating_system filter can only have a major and minor version.")
elif len(version_split) == 1: # only major version was sent
major = version_split[0]
minor = None
else:
major, minor = version_split

if not major.isdigit() or (minor and not minor.isdigit()):
raise ValidationException("operating_system major and minor versions must be numerical.")
except ValidationException:
raise

self.name = name
self.comparator = comparator
Expand Down

0 comments on commit 5403b89

Please sign in to comment.