strapi / strapi

🚀 Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable, and developer-first.
https://strapi.io
Other
63.8k stars 8.13k forks source link

REST API filters $contains operator not working in Strapi Cloud environment #20367

Open hunganhAtWhill opened 5 months ago

hunganhAtWhill commented 5 months ago

Bug report

Required System information

Describe the bug

In my local environment, I can use /api/my-content?filters[fieldName][$contains]=somevalue without issues, but in Strapi cloud deployed environment /api/my-content?filters[fieldName][$contains]=somevalue returns 500 error. Checking the runtime logs it is saying $contains operator does not exist. I can use /api/my-content?filters[fieldName][$containsi]=somevalue without problem though. Also, I am using a plugin called Multi Select Input for the field in question

Steps to reproduce the behavior

  1. Go to https://accidental-loud-pets.strapiapp.com/api/news?locale=en&publicationState=live&filters[categories][$contains]=product
  2. Get 500 error
  3. Check the runtime logs
  4. See the operator not exists error
  5. If using $containsi instead of $contains, it works

Expected behavior

Can use $contains operator

Screenshots

Screenshot 2024-05-24 at 18 21 32 Screenshot 2024-05-24 at 18 21 18

Code snippets

Runtime logs

[2024-05-24 09:04:41] [2024-05-24 09:04:41.141] http: GET /api/news-pieces?locale=en&publicationState=live&filters[categories][$contains]=product (7 ms) 404
[2024-05-24 09:04:47] [2024-05-24 09:04:47.479] error: select "t0".* from "public"."news" as "t0" where (("t0"."locale" = $1 and "t0"."categories" like $2) and "t0"."published_at" is not null) limit $3 - operator does not exist: jsonb ~~ unknown
[2024-05-24 09:04:47] error: select "t0".* from "public"."news" as "t0" where (("t0"."locale" = $1 and "t0"."categories" like $2) and "t0"."published_at" is not null) limit $3 - operator does not exist: jsonb ~~ unknown
[2024-05-24 09:04:47]     at Parser.parseErrorMessage (/home/app/node_modules/pg-protocol/dist/parser.js:283:98)
[2024-05-24 09:04:47]     at Parser.handlePacket (/home/app/node_modules/pg-protocol/dist/parser.js:122:29)
[2024-05-24 09:04:47]     at Parser.parse (/home/app/node_modules/pg-protocol/dist/parser.js:35:38)
[2024-05-24 09:04:47]     at TLSSocket.<anonymous> (/home/app/node_modules/pg-protocol/dist/index.js:11:42)
[2024-05-24 09:04:47]     at TLSSocket.emit (node:events:517:28)
[2024-05-24 09:04:47]     at TLSSocket.emit (node:domain:489:12)
[2024-05-24 09:04:47]     at addChunk (node:internal/streams/readable:368:12)
[2024-05-24 09:04:47]     at readableAddChunk (node:internal/streams/readable:341:9)
[2024-05-24 09:04:47]     at Readable.push (node:internal/streams/readable:278:10)
[2024-05-24 09:04:47]     at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)

Additional context

I am using a plugin called Multi Select Input for the field in question Also, I suspect this might apply to graphql as well, if using filters with contains operator.

joaoprcosta commented 4 days ago

The same is happening with me. Works fine using $containsi but shouldn't be case sensitive.