Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Revert product resource clean method #59

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions oscar_odin/resources/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

import odin
from odin.fields import StringField
from odin.exceptions import ValidationError as OdinValidationError, NON_FIELD_ERRORS

from ..fields import DecimalField

OscarResource = get_class("oscar_odin.resources.base", "OscarResource")

PartnerResource = get_class("oscar_odin.resources.partner", "PartnerResource")
StockRecordResource = get_class("oscar_odin.resources.partner", "StockRecordResource")

ProductModel = get_model("catalogue", "Product")
Expand Down Expand Up @@ -137,28 +135,3 @@ class ProductResource(OscarCatalogueResource):
children: Optional[List["ProductResource"]] = odin.ListOf.delayed(
lambda: ProductResource, null=True
)

def clean(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure that there is validation that ensures partner and upc (and currency?) are present when either price or availability is not None.

The mapping checks for these to be present and will fail silently if this is not true

if (
not self.stockrecords
and (self.price is not None or self.availability is not None)
and not (
self.upc is not None
and self.currency is not None
and self.partner is not None
)
):
errors = {
NON_FIELD_ERRORS: [
"upc, currency and partner are required when specifying price or availability"
]
}
# upc is allready required so we don't need to check for it here
if (
self.currency is None
): # currency has a default but it can be set to null by accident
errors["currency"] = ["Currency can not be empty."]
if self.partner is None:
errors["partner"] = ["Partner can not be empty."]

raise OdinValidationError(errors, code="simpleprice")
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file removed tests/resources/__init__.py
Empty file.
85 changes: 0 additions & 85 deletions tests/resources/test_catalogue.py

This file was deleted.

Loading