Saleor: Stock.DoesNotExist after ProductVariant Creation

Created on 20 Jan 2020  路  11Comments  路  Source: mirumee/saleor

What 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

  1. I cloned Saleor repository from master with merged #4986 PR.
  2. I cloned Saleor Dashboard from master
  3. I have set up both saleor and saleor-dashboard
  4. I created 2 attributes, 1 product type, 1 category.
  5. I created a Product with the above options
  6. 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

Screenshot from 2020-01-21 01-20-54
Screenshot from 2020-01-21 01-22-02

System information
Operating system: Ubuntu 18.04
Python: 3.8
Django: 2.2.9
PostgreSQL: 12.1

bug

Most helpful comment

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.

All 11 comments

Hi,

Did that mean that when migrations are just being executed for the first time, no warehouse is going to be created?

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.

Hi. Thanks for your response @szewczykmira.

Hmm. As far as I understood, the quantity of a product variant is now dependent on stock and increasing or decreasing will definitely affect the stock. So changing the function resolve_quantity_allocated by covering with try-except won't help? :

def resolve_quantity_allocated(root: models.ProductVariant, info):
        country = info.context.country
        try:
            stock = stock_models.Stock.objects.get_variant_stock_for_country(country, root)
            return stock.quantity_allocated
        except stock_models.Stock.DoesNotExist:
            return 0

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.

@maarcingebala ok, thank you. Can't wait to see it :smile:

I ran into this error a moment ago while querying stockQuantity in variants. In addition to that, all the products were listed as "Not Published" on the dashboard. In my case, the store had no shipping zones configured on saleor (logistics are handled externally).

To fix this, I had to add a shipping zone that covered the DEFAULT_COUNTRY. And then I assigned it to the default Warehouse object's shipping_zones. I suspect that if one's services cover multiple countries, then the shipping zone should cover all the countries.

Please also note that since API and Dashboard are two separate apps, it may happen that master branches in both repos may not be 100% compatible all the time. It's not so clear in the docs (we need to improve it) but for stable versions we recommend using the release tags:

How's info.context.country resolved when, for example, updating ProductVariant quantity?
It uses info.context.country, but how country is determined? Is it default country? Is it HttpHeader?

Is there any indication as to when this feature will be on the dashboard? I ran into the same error and wondered the same as @Boquete. Since there's no way to add inventory without a warehouse management, is there a suggestion to handle this properly.

Same issue here. I created a single product, but can't increase the stock. Furthermore, the product is always shown as "not published".
It's sad, that there are new features added, that completely brick the existing, normal flows .. and there is no fix since January :(

Hi,
I'm not with the core team anymore, but I see that last stable version is 2.9.1. Could you check if this one is working for you? Please remember to recreate the database, as warehouses and stocks are not in the stable version.

This one should be already fixed in 2.10 release.

Was this page helpful?
0 / 5 - 0 ratings