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

Search by collection returns null for productVariantAsset even though set in admin dashboard #2907

Closed
casperiv0 opened this issue Jun 17, 2024 · 13 comments
Labels
type: bug 🐛 Something isn't working

Comments

@casperiv0
Copy link
Contributor

casperiv0 commented Jun 17, 2024

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:

  1. Go to a product and set a featured asset
  2. Go to a product variant within that product and set a featured asset
  3. Use the query below
  4. See that the productVariantAsset is null and productAsset is not null.

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
      }
    }
@casperiv0 casperiv0 added the type: bug 🐛 Something isn't working label Jun 17, 2024
@casperiv0
Copy link
Contributor Author

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 😅

@michaelbromley
Copy link
Member

Is the worker running and updating the search index on changes to the entities?

@casperiv0
Copy link
Contributor Author

Yeah, looks like it ran successfully:

image

However, it did not update the search index when running the search query

@michaelbromley
Copy link
Member

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?

@casperiv0
Copy link
Contributor Author

Nope, doesn't look like it:

In Vendure:
image

Search API result:
image

@michaelbromley
Copy link
Member

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.

@casperiv0
Copy link
Contributor Author

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

@ankenu
Copy link

ankenu commented Jul 8, 2024

@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 }),

@michaelbromley
Copy link
Member

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

@michaelbromley
Copy link
Member

This was fixed by the PR mentioned above. Will be available in the next patch release.

@casperiv0
Copy link
Contributor Author

Awesome, thank you!!

@kartikjethani-solidity
Copy link

I am facing the same issue. When can we expect this patch release, please?

@michaelbromley
Copy link
Member

today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants