Craft Commerce hasStock not working? I'm trying to query for certain products but only ones that have stock (the products just have defaultVariants):

{% set earliestDate = now | date_modify('- 1 days') %} 
{% set latestDate = now | date_modify('+ 10 days') %}
{% set products = craft.commerce.products({
    hasVariants: {
        hasStock: true
    },
    type: 'class',
    date: 'and, &gt; ' ~ earliestDate ~ ', &lt; ' ~ latestDate,
    order: 'date',
    limit: 5
}) %}


The above returns 5 products, all of which happen to have no stock left as identified by them not showing when I use:

{% if product.defaultVariant.stock &gt; 0 %}
    {{ product.title }}
{% endif %}


I'm currently getting products to show by setting the limit to 25 and then it only shows 1 product in stock. Meaning the query is returning 25 products, of which 24 have no stock so shouldn't be returned.

Running Craft Commerce 1.2.1337 so am up-to-date.

Could be related to: Commerce products returning different results on page load

Someone else mentioning it in comment to answer of this: How do I check if a product has stock in any of it&#39;s variants?
Your product element criteria is using a condition param: hasVariants, but it should be hasVariant as per the docs: https://craftcommerce.com/docs/craft-commerce-products#hasvariant

That correctly only returns products (where a variant that belongs to that product) is in stock.