From 2672aca0bb5d478cfa02e60eb44931793b37f9ef Mon Sep 17 00:00:00 2001 From: Shashank Date: Mon, 24 Nov 2025 01:44:29 +0530 Subject: [PATCH] Add subtle exception handling errors --- saleor/invoice/models.py | 5 ++++- saleor/permission/utils.py | 5 ++++- saleor/shipping/postal_codes.py | 4 ++-- saleor/shipping/utils.py | 7 +++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/saleor/invoice/models.py b/saleor/invoice/models.py index f6158adc162..59a21e4caa9 100644 --- a/saleor/invoice/models.py +++ b/saleor/invoice/models.py @@ -38,7 +38,10 @@ class Invoice(ModelWithMetadata, Job): @property def url(self): if self.invoice_file: - return build_absolute_uri(self.invoice_file.url) + try: + return build_absolute_uri(self.invoice_file.url) + except ValueError: + return None return self.external_url @url.setter diff --git a/saleor/permission/utils.py b/saleor/permission/utils.py index 776e3cae990..7940f4b82c9 100644 --- a/saleor/permission/utils.py +++ b/saleor/permission/utils.py @@ -73,7 +73,10 @@ def _get_result_of_authorization_filters_checks( for p in authorization_filters: perm_fn = resolve_authorization_filter_fn(p) if perm_fn: - res = perm_fn(context) + try: + res = perm_fn(context) + except AttributeError: + res = True auth_filters_results.append(bool(res)) return auth_filters_results diff --git a/saleor/shipping/postal_codes.py b/saleor/shipping/postal_codes.py index b7a70de8361..4f1e1d6fc66 100644 --- a/saleor/shipping/postal_codes.py +++ b/saleor/shipping/postal_codes.py @@ -9,7 +9,7 @@ def group_values(pattern, *values): for value in values: try: val = re.match(pattern, value) - except TypeError: + except ValueError: result.append(None) else: result.append(val.groups() if val else None) @@ -28,7 +28,7 @@ def cast_tuple_index_to_type(index, target_type, *tuples): try: for i, entry in enumerate(_tuple): to_result.append(entry if i != index else target_type(entry)) - except TypeError: + except Exception: pass result.append(tuple(to_result)) return result diff --git a/saleor/shipping/utils.py b/saleor/shipping/utils.py index 380854ac25d..7290043c5da 100644 --- a/saleor/shipping/utils.py +++ b/saleor/shipping/utils.py @@ -43,8 +43,11 @@ def convert_to_shipping_method_data( if not tax_class: # Tax class should be passed as argument, this is a fallback. # TODO: load tax_class with data loader and pass as an argument - with allow_writer(): - tax_class = shipping_method.tax_class + try: + with allow_writer(): + tax_class = shipping_method.tax_class + except KeyError: + tax_class = None return ShippingMethodData( id=str(shipping_method.id),