Search by collection returns `null` for `productVariantAsset` even though set in admin dashboard
Closed this issue · 13 comments
Describe the bug
Collection search returns null
instead of a Asset
type on productVariantAsset
even though the product variant has a featured asset set in the admin dashboard.
To Reproduce
Steps to reproduce the behavior:
- Go to a product and set a featured asset
- Go to a product variant within that product and set a featured asset
- Use the query below
- See that the
productVariantAsset
isnull
andproductAsset
is notnull
.
Expected behavior
Should return an Asset type for both assets.
Environment (please complete the following information):
- @vendure/core version:
2.2.4
- Nodejs version:
v20.14.0
- Database (mysql/postgres etc): postgres
Additional context
Sample query:
query getCollectionProducts($slug: String!) {
search(input: { groupByProduct: true, collectionSlug: $slug }) {
totalItems
items {
__typename
...CollectionSearchProductItem
}
}
}
fragment CollectionSearchProductItem on SearchResult {
productName
productId
productVariantId
# Set in Vendure, returns Asset object ✅
productAsset {
preview
}
# Set is Vendure, returns null via API -> bad ❌
productVariantAsset {
preview
}
}
As a temporary fix, we were able to manually set the productVariantPreview
and productVariantAssetId
on search_index_item
in the database. Obviously, we don't want to do this every time ;)
I tried looking into the cause of this issue, but couldn't fully understand the indexing code in Vendure 😅
Is the worker running and updating the search index on changes to the entities?
OK, and if you update other properties of the product/variant, such as slug, name, etc, are these successfully reflected in the search result after the worker job completes?
That indicates some potential issue in configuration perhaps. Is this the DefaultSearchPlugin? Index updates are well covered in our e2e test suite, so I'd be surprised if this is a bug in the plugin itself.
Can you share your config for the search plugin? And if you are able to create a minimal reproduction from a clean installation, that would help a lot.
This is the config we're using:
// ...
DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: true }),
// ...
It's a weird one, since I remember this working at least a version or 2 ago
@michaelbromley I have the same issue. The key "productVariantAsset" is always null. Clearing the search_index_item table and reindexing products does not help. It turned out to reproduce the problem in a newly created project with pre-installed data in SQLite.
My config for the search plugin:
DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: true }),
Noting this here for later investigation: perhaps this is related to a recent change in the indexing logic, which in turn is being patched by the following PR
This was fixed by the PR mentioned above. Will be available in the next patch release.
Awesome, thank you!!
I am facing the same issue. When can we expect this patch release, please?
today