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:
parent
3fbe6883c7
commit
39e120e8c6
1 changed files with 24 additions and 7 deletions
31
engine/core/vendors/__init__.py
vendored
31
engine/core/vendors/__init__.py
vendored
|
|
@ -155,8 +155,12 @@ class AbstractVendor:
|
||||||
filename = f"response_{timestamp}.json"
|
filename = f"response_{timestamp}.json"
|
||||||
content = ContentFile(json_bytes)
|
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)
|
vendor_instance.last_processing_response.save(filename, content, save=True)
|
||||||
|
|
||||||
|
self.log(LogLevel.DEBUG, f"Saved vendor's response to {filename} successfuly!")
|
||||||
|
|
||||||
return
|
return
|
||||||
raise VendorDebuggingError("Could not save response")
|
raise VendorDebuggingError("Could not save response")
|
||||||
|
|
||||||
|
|
@ -451,17 +455,23 @@ class AbstractVendor:
|
||||||
|
|
||||||
return attr
|
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:
|
if not value:
|
||||||
self.log(LogLevel.WARNING, f"No value for attribute {key!r} at {product.name!r}...")
|
self.log(LogLevel.WARNING, f"No value for attribute {key!r} at {product.name!r}...")
|
||||||
return
|
return None
|
||||||
|
|
||||||
if not attr_group:
|
if not attr_group:
|
||||||
self.log(LogLevel.WARNING, f"No group for attribute {key!r} at {product.name!r}...")
|
self.log(LogLevel.WARNING, f"No group for attribute {key!r} at {product.name!r}...")
|
||||||
return
|
return None
|
||||||
|
|
||||||
if key in self.blocked_attributes:
|
if key in self.blocked_attributes:
|
||||||
return
|
return None
|
||||||
|
|
||||||
value, attr_value_type = self.auto_convert_value(value)
|
value, attr_value_type = self.auto_convert_value(value)
|
||||||
|
|
||||||
|
|
@ -498,18 +508,25 @@ class AbstractVendor:
|
||||||
raise
|
raise
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
self.log(LogLevel.WARNING, f"IntegrityError while processing attribute {key!r}...")
|
self.log(LogLevel.WARNING, f"IntegrityError while processing attribute {key!r}...")
|
||||||
return
|
return None
|
||||||
|
|
||||||
if not is_created:
|
if not is_created:
|
||||||
return
|
return None
|
||||||
|
|
||||||
AttributeValue.objects.get_or_create(
|
av, _ = AttributeValue.objects.get_or_create(
|
||||||
attribute=attribute,
|
attribute=attribute,
|
||||||
value=value,
|
value=value,
|
||||||
product=product,
|
product=product,
|
||||||
defaults={"is_active": True},
|
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:
|
def update_stock(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue