Skip to content

[bug]: Not Parsing Params Properly When using Or Statement. #41

@PaulBratslavsky

Description

@PaulBratslavsky

Bug Description

When using the SDK and filtering, I am getting a 500 error.

Steps to Reproduce

Steps to reproduce

  1. Setup Strapi project
  2. Setup Next.js project using SDK
  3. Run a find query passing parameters via or in the filter

example query:

// TODO: FIX THE SEARCH QUERY
export async function getBlogPosts(
  page: number,
  queryString: string,
  category: string
) {
  const posts = await sdk.collection("posts").find({
    populate: "*",
    filters: {
      category: { text: { $containsi: "tech" } },
      $or: [
        { title: { $containsi: "cms" } },
        { description: { $containsi: "cms" } },
      ],
    },
  });
  return posts;

Here is the example in my project: https://github.com/PaulBratslavsky/strapi-5-next-js-starter-project/blob/251e560e5f274ba496ba748b3380e5607f254d32/client/src/data/loaders/index.ts#L149-L153

This will cause the app to error.

Error Message

Here is the error message that I get

[2025-01-31 13:40:07.540] error: Where must be an array or an object
Error: Where must be an array or an object
    at applyWhere (/Users/paul/pauls-strapi-playground/server/node_modules/@strapi/database/dist/index.js:4225:11)
    at QueryBuilder_SQLite3.<anonymous> (/Users/paul/pauls-strapi-playground/server/node_modules/@strapi/database/dist/index.js:4242:55)
    at compileCallback (/Users/paul/pauls-strapi-playground/server/node_modules/knex/lib/formatter/formatterUtils.js:7:12)
    at rawOrFn (/Users/paul/pauls-strapi-playground/server/node_modules/knex/lib/formatter/wrappingFormatter.js:225:7)
    at QueryCompiler_SQLite3.whereWrapped (/Users/paul/pauls-strapi-playground/server/node_modules/knex/lib/query/querycompiler.js:1095:17)
    at QueryCompiler_SQLite3.where (/Users/paul/pauls-strapi-playground/server/node_modules/knex/lib/query/querycompiler.js:584:34)
    at QueryCompiler_SQLite3.toSQL (/Users/paul/pauls-strapi-playground/server/node_modules/knex/lib/query/querycompiler.js:75:29)

When the console login where, I get this

**********  applyWhere ********** [
  {
    't0.published_at': { '$notNull': true },
    't2.text': { '$containsi': 'tech' },
    '$or': [ '[object Object]', '[object Object]' ]
  },
  { 't0.published_at': { '$null': false } }
]
**********  applyWhere ********** {
  't0.published_at': { '$notNull': true },
  't2.text': { '$containsi': 'tech' },
  '$or': [ '[object Object]', '[object Object]' ]
}
**********  applyWhere ********** { 't0.published_at': { '$null': false } }
**********  applyWhere ********** [object Object]

You can see on the last line that it is not parsed correctly.

Expected Behavior

Should filter based on provided queries.

Version

1.0.0-beta.1

Operating System

MacOS

Runtime Environment

Node.js

Logs

Media

No response

Confirmation Checklist

  • I have checked the existing issues
  • I agree to follow this project's Code of Conduct
  • I would like to work on this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bugseverity: mediumIf it breaks the basic use of the product but can be worked aroundstatus: confirmedThe issue has been confirmed or reproduced manually by a team member

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions