Features: 1) Add logging for saving vendor responses and processing attributes; 2) Update process_attribute to return AttributeValue upon success.

Fixes: 1) Replace missing return values with `None` in `process_attribute` for clarity; 2) Correct typo in debug log messaging.

Extra: 1) Update method definitions for readability; 2) Improve logging granularity and structure.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-11-10 08:44:36 +03:00
parent 3fbe6883c7
commit 39e120e8c6

View file

@ -155,8 +155,12 @@ class AbstractVendor:
filename = f"response_{timestamp}.json"
content = ContentFile(json_bytes)
self.log(LogLevel.DEBUG, f"Saving vendor's response to {filename}")
vendor_instance.last_processing_response.save(filename, content, save=True)
self.log(LogLevel.DEBUG, f"Saved vendor's response to {filename} successfuly!")
return
raise VendorDebuggingError("Could not save response")
@ -451,17 +455,23 @@ class AbstractVendor:
return attr
def process_attribute(self, key: str, value: Any, product: Product, attr_group: AttributeGroup) -> None:
def process_attribute(
self, key: str, value: Any, product: Product, attr_group: AttributeGroup
) -> AttributeValue | None:
self.log(
LogLevel.DEBUG, f"Trying to save attribute {key} with value {value} to {attr_group.name} of {product.pk}"
)
if not value:
self.log(LogLevel.WARNING, f"No value for attribute {key!r} at {product.name!r}...")
return
return None
if not attr_group:
self.log(LogLevel.WARNING, f"No group for attribute {key!r} at {product.name!r}...")
return
return None
if key in self.blocked_attributes:
return
return None
value, attr_value_type = self.auto_convert_value(value)
@ -498,18 +508,25 @@ class AbstractVendor:
raise
except IntegrityError:
self.log(LogLevel.WARNING, f"IntegrityError while processing attribute {key!r}...")
return
return None
if not is_created:
return
return None
AttributeValue.objects.get_or_create(
av, _ = AttributeValue.objects.get_or_create(
attribute=attribute,
value=value,
product=product,
defaults={"is_active": True},
)
self.log(
LogLevel.DEBUG,
f"Succesfully saved attribute {key} with value {value} to {attr_group.name} of {product.pk} into {av.uuid}",
)
return av
def update_stock(self) -> None:
pass