Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve the debug representation of CheckoutLine and CheckoutLineInfo (#18626)
Patryk Zawadzki71e51650abc5
diff --git a/saleor/checkout/fetch.py b/saleor/checkout/fetch.pyindex 59a80ead75..ddf87afde6 100644--- a/saleor/checkout/fetch.py+++ b/saleor/checkout/fetch.py@@ -59,10 +59,10 @@ class CheckoutLineInfo(LineInfo):product: "Product"product_type: "ProductType"discounts: list["CheckoutLineDiscount"]- rules_info: list["VariantPromotionRuleInfo"]- channel_listing: Optional["ProductVariantChannelListing"]+ rules_info: list["VariantPromotionRuleInfo"] = field(repr=False)+ channel_listing: Optional["ProductVariantChannelListing"] = field(repr=False)- tax_class: Optional["TaxClass"] = None+ tax_class: Optional["TaxClass"] = field(default=None, repr=False)@cached_propertydef variant_discounted_price(self) -> Money:diff --git a/saleor/checkout/models.py b/saleor/checkout/models.pyindex f97dbf667c..6906af63a1 100644--- a/saleor/checkout/models.py+++ b/saleor/checkout/models.py@@ -509,7 +509,7 @@ class CheckoutLine(ModelWithMetadata):return not self == other # pragma: no coverdef __repr__(self):- return f"CheckoutLine(variant={self.variant!r}, quantity={self.quantity!r})"+ return f"<CheckoutLine: variant={self.variant!r}, quantity={self.quantity!r}, total={self.total_price_gross_amount} {self.currency}>"def __getstate__(self):return self.variant, self.quantitydiff --git a/saleor/checkout/tests/test_cart.py b/saleor/checkout/tests/test_cart.pyindex b60784319e..4090f6673d 100644--- a/saleor/checkout/tests/test_cart.py+++ b/saleor/checkout/tests/test_cart.py@@ -264,7 +264,8 @@ def test_checkout_line_repr(product, checkout_with_single_item):variant = product.variants.get()line = checkout_with_single_item.lines.first()assert (- repr(line) == f"CheckoutLine(variant={variant!r}, quantity={line.quantity!r})"+ repr(line)+ == f"<CheckoutLine: variant={variant!r}, quantity={line.quantity!r}, total=0.000 USD>")diff --git a/saleor/core/pricing/interface.py b/saleor/core/pricing/interface.pyindex 3c7057c269..4228c39482 100644--- a/saleor/core/pricing/interface.py+++ b/saleor/core/pricing/interface.py@@ -1,5 +1,5 @@from collections.abc import Iterable-from dataclasses import dataclass+from dataclasses import dataclass, fieldfrom typing import TYPE_CHECKING, Optional, Unionfrom ...discount import DiscountType@@ -23,8 +23,8 @@ class LineInfo:variant: Optional["ProductVariant"]product: Optional["Product"]product_type: Optional["ProductType"]- collections: list["Collection"]- channel: "Channel"+ collections: list["Collection"] = field(repr=False)+ channel: "Channel" = field(repr=False)discounts: Iterable[Union["OrderLineDiscount", "CheckoutLineDiscount"]]voucher: Optional["Voucher"]voucher_code: str | Nonediff --git a/saleor/product/models.py b/saleor/product/models.pyindex 532dbd1c77..ccebb36cd4 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -165,8 +165,7 @@ class ProductType(ModelWithMetadata):return self.namedef __repr__(self) -> str:- class_ = type(self)- return f"<{class_.__module__}.{class_.__name__}(pk={self.pk!r}, name={self.name!r})>"+ return f"<ProductType: pk={self.pk!r}, name={self.name!r}>"class Product(SeoModel, ModelWithMetadata, ModelWithExternalReference):@@ -247,8 +246,7 @@ class Product(SeoModel, ModelWithMetadata, ModelWithExternalReference):return iter(getattr(self, "__variants"))def __repr__(self) -> str:- class_ = type(self)- return f"<{class_.__module__}.{class_.__name__}(pk={self.pk!r}, name={self.name!r})>"+ return f"<Product: pk={self.pk!r}, name={self.name!r}>"def __str__(self) -> str:return self.name