Fixes: 1) Handle missing DigitalAssetDownload instance in download_url method with explicit conditional logic;

Extra: 1) Simplify exception handling by replacing it with clear branch logic.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-10-03 17:26:58 +03:00
parent 90d077fefd
commit 9ad79f0c5e

View file

@ -1784,9 +1784,9 @@ class OrderProduct(ExportModelOperationsMixin("order_product"), NiceModel): # t
def download_url(self: Self) -> str: def download_url(self: Self) -> str:
if self.product and self.product.stocks: if self.product and self.product.stocks:
if self.product.is_digital and self.product.stocks.first().digital_asset: # type: ignore [union-attr] if self.product.is_digital and self.product.stocks.first().digital_asset: # type: ignore [union-attr]
try: if self.download:
return self.download.url return self.download.url
except DigitalAssetDownload.RelatedObjectDoesNotExist: else:
return DigitalAssetDownload.objects.create(order_product=self).url return DigitalAssetDownload.objects.create(order_product=self).url
return "" return ""