Refactor attribute handling in vendor module: update type annotations and simplify get_or_create logic.

This commit is contained in:
Egor Pavlovich Gorbunov 2025-12-27 01:08:56 +03:00
parent b6d38d07e5
commit 646fc5e1d7

View file

@ -397,7 +397,7 @@ class AbstractVendor:
f"No matching vendor found with name {self.vendor_name!r}..." f"No matching vendor found with name {self.vendor_name!r}..."
) from dne ) from dne
def get_products(self) -> None: def get_products(self) -> Any:
pass pass
def get_products_queryset(self) -> QuerySet[Product]: def get_products_queryset(self) -> QuerySet[Product]:
@ -523,13 +523,11 @@ class AbstractVendor:
value, attr_value_type = self.auto_convert_value(value) value, attr_value_type = self.auto_convert_value(value)
is_created = False
if len(key) > 255: if len(key) > 255:
key = key[:255] key = key[:255]
try: try:
attribute, is_created = Attribute.objects.get_or_create( attribute, _ = Attribute.objects.get_or_create(
name=key, name=key,
group=attr_group, group=attr_group,
value_type=attr_value_type, value_type=attr_value_type,
@ -565,9 +563,6 @@ class AbstractVendor:
) )
return None return None
if not is_created:
return None
av, _ = AttributeValue.objects.get_or_create( av, _ = AttributeValue.objects.get_or_create(
attribute=attribute, attribute=attribute,
value=value, value=value,