Stock.DoesNotExist after ProductVariant Creation
See original GitHub issueWhat I’m trying to achieve
To test the system for the first time by creating product variants. I got an error of saleor.warehouse.models.Stock.DoesNotExist
when I was creating ProductVariant for an existing product.
Steps to reproduce the problem
- I cloned Saleor repository from master with merged #4986 PR.
- I cloned Saleor Dashboard from master
- I have set up both saleor and saleor-dashboard
- I created 2 attributes, 1 product type, 1 category.
- I created a Product with the above options
- I created for this existing product 6 product variants and then got an error
What I expected to happen
I hope ProductVariants had to be created without any errors, because if I had to create warehouse first, then this feature needed to be in saleor-dashboard, but I could not find it. What is more interesting, I guess according to the migration inside warehouse app, at least one warehouse needed to be created and but none was created. I was also curious about thoughts of @szewczykmira:
In my approach - we will create warehouse if a) there are some product variants created and b) there is no other warehouse that supports all shipping zones.
Did that mean that when migrations are just being executed for the first time, no warehouse is going to be created? if yes, then it means that there may not be warehouse object in the system at all and it implies that there will not be stock object too. Then:
class ProductVariant(CountableDjangoObjectType, MetadataObjectType):
...
def resolve_stock_quantity(root: models.ProductVariant, info):
country = info.context.country
try:
stock = stock_models.Stock.objects.get_variant_stock_for_country(
country, root
)
except stock_models.Stock.DoesNotExist:
return 0
return get_available_quantity_for_customer(stock)
...
def resolve_quantity_allocated(root: models.ProductVariant, info):
country = info.context.country
stock = stock_models.Stock.objects.get_variant_stock_for_country(country, root)
return stock.quantity_allocated
Why there is try-except in the first function, but there is no try-except in the second function? I am sorry if I was not clear about the error, and please let me know if I need to explain it more details
Screenshots
System information Operating system: Ubuntu 18.04 Python: 3.8 Django: 2.2.9 PostgreSQL: 12.1
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:11 (8 by maintainers)
Thanks for opening the issue @bedilbek. We’re working on a fix for this and for updating stock quantity with current mutations. Dashboard UI for this entire feature is ready and we’re going to start building it in our next sprint which starts at the end of January.
Hi,
Exactly, creating warehouse happens only when there is existing product variant and there are stocks we need to migrate to the new model.
As you’ve noticed there are no warehouse/stock options in saleor-dashboard and this feature will be introduced there (but I’m not sure exactly when that will happen).
As for now - I’m working on a temporary fix - creating a Stock object (and warehouse) when there is none in the database.