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

Add product price validation #5413

Merged
merged 6 commits into from
Apr 2, 2020

Conversation

kswiatek92
Copy link

closes #5326

Pull Request Checklist

  • Privileged queries and mutations are guarded by proper permission checks
  • Database queries are optimized and the number of queries is constant
  • Database migration files are up to date
  • The changes are tested
  • GraphQL schema and type definitions are up to date
  • Changes are mentioned in the changelog

@codecov
Copy link

codecov bot commented Mar 30, 2020

Codecov Report

Merging #5413 into master will decrease coverage by 0.01%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5413      +/-   ##
==========================================
- Coverage   91.13%   91.11%   -0.02%     
==========================================
  Files         283      283              
  Lines       18329    18343      +14     
  Branches     1608     1613       +5     
==========================================
+ Hits        16704    16714      +10     
- Misses       1196     1200       +4     
  Partials      429      429
Impacted Files Coverage Δ
saleor/graphql/product/mutations/products.py 95.84% <100%> (+0.03%) ⬆️
saleor/graphql/product/bulk_mutations/products.py 98.03% <50%> (+0.02%) ⬆️
saleor/core/utils/draftjs.py 20% <0%> (-10%) ⬇️
saleor/product/models.py 91.11% <0%> (-0.4%) ⬇️
saleor/graphql/shipping/mutations.py 97.53% <0%> (-0.04%) ⬇️
saleor/demo/settings.py 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9b47db...bc827e2. Read the comment docs.

@maarcingebala
Copy link
Member

@kswiatek92 There are a few more places where we can set prices in API.

We have costPrice and priceOverride fields in:

  • productVariantUpdate
  • productVariantCreate
  • productVariantBulkCreate

We should ensure that we have validation there as well. If it makes sense maybe we should add a function that does this validation and raises this error so don't have to duplicate entire ValidationError multiple times.

@kswiatek92
Copy link
Author

@maarcingebala I don't think it's necessary,
there are only 3 places where this validation occurs, for different fields. To make it work properly, such function should have additional argument for field, and maybe message error, which make such function just ValidationError with different name

@fowczarek
Copy link
Member

@kswiatek92
You can create function without restriction that you write.
As a function argument, you can pass price instead of mutation input. And function can return validation error with the message and you should catch this error in mutation body and add required ErrorCode.

@maarcingebala What do you think about introducing a specific error code for this validation?

CHANGELOG.md Outdated Show resolved Hide resolved
saleor/graphql/product/bulk_mutations/products.py Outdated Show resolved Hide resolved
saleor/graphql/product/bulk_mutations/products.py Outdated Show resolved Hide resolved
saleor/graphql/product/mutations/products.py Outdated Show resolved Hide resolved
saleor/graphql/product/mutations/products.py Outdated Show resolved Hide resolved
saleor/graphql/product/mutations/products.py Outdated Show resolved Hide resolved
saleor/graphql/product/mutations/products.py Outdated Show resolved Hide resolved
@fowczarek fowczarek self-requested a review April 1, 2020 08:33
@kswiatek92 kswiatek92 force-pushed the validate-product-price branch 2 times, most recently from 36119c4 to 1933e6b Compare April 1, 2020 11:45
@maarcingebala maarcingebala merged commit a1a2831 into saleor:master Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It should not be possible to set negative prices
5 participants