craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.21k stars 624 forks source link

[4.x]: Inconsistent entry results when using specific schema #13896

Closed patrikalienus closed 10 months ago

patrikalienus commented 10 months ago

What happened?

Description

We have a query that fetches entries from section articles through search functionality. This works as expected however the returned articles are not consistent. A query that should return 1 entry, sometimes returns 0 entries. However this only happens when using a specific schema. If I switch to using the Full schema the problem goes away.

The schema (Nuxt) we're targeting contains everything except for mutations.

This is the query we're using:

query ($site: [String]!, $offset: Int!, $limit: Int!, $searchTerm: String, $category: [String]) {
  entryCount(
    section: "articles"
    site: $site
    search: $searchTerm
    relatedToCategories: [{slug: $category}]
  )
  articles: entries(
    section: "articles"
    site: $site
    offset: $offset
    limit: $limit
    search: $searchTerm
    relatedToCategories: [{slug: $category}]
  ) {
    id
    searchScore
  }
}

Query variables:

{
  "site": "swedish",
  "offset": 0,
  "limit": 10,
  "searchTerm": "loppor",
  "category": "katt"
}

I made a screen recording to show this behaviour. https://youtu.be/MbqzjB85ymY

Steps to reproduce

  1. Create a custom schema, include everything except mutations
  2. Write the above/similar query into GraphiQL and execute it

Expected behavior

The same response each time.

Actual behavior

Different response each time.

Craft CMS version

Craft Pro 4.5.6.1

PHP version

8.2.11

Operating system and version

Linux 5.10.192-183.736.amzn2.x86_64

Database type and version

MySQL 5.7.42

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.1-13)

Installed plugins and versions

Blitz 4.5.5 Colorit 4.0.0 Cookies 4.0.0 Element API 3.0.1.1 Feed Me 5.2.0 HTTP/2 Server Push Twig 2.0.2 Icon Picker 2.0.14 Image Resizer 3.0.7 Imager X 4.2.3 Mailgun 3.0.0 Minify 4.0.0-beta.2 Navigation 2.0.21 Neo 3.9.4 Preparse Field 2.0.2 Redactor 3.0.4 Retour 4.1.13 Sentry SDK 2.0.1 SEOmatic 4.0.31 Shortcodes 3.0.0 Vite 4.0.6

i-just commented 10 months ago

Hi, thanks for reaching out!

I’m having trouble replicating this behaviour. Any chance you could disable all the plugins and see if this still happens?

patrikalienus commented 10 months ago

@i-just Hi, thanks for looking into it.

I'm wondering what difference it would make to disable all plugins (some are required for the data to work at all, like Neo fields for instance,) since it works just fine with the "Full schema" setting.

i-just commented 10 months ago

Hi @patrikalienus, since I’m not able to replicate it on a clean Craft CMS instance, I thought it was worth checking if you’re still experiencing the same behaviour when all plugins are disabled. If that’s not an option, could you please send your composer.json, composer.lock and database export to support@craftcms.com so we can look into it?

patrikalienus commented 10 months ago

Ah ok I see. I will send a message to support.

patrikalienus commented 10 months ago

For anyone finding this thread at a later date:

The reason for this weird issue, was due to the sites within the group having the same sortOrder. I don't know how this happened as it was before my time with the project, but it had an effect with this particular query.

The fix is thus quite simple: Re-order the sites under Settings > Sites > [Group] and that should update the sortOrder in the database and re-write the relevant project-config files.

brandonkelly commented 10 months ago

Craft 4.5.10 is out now, which is defensive against multiple sites sharing the same sortOrder value. Thanks again for reporting!