When I use $in inside $or in ctx.request, it throws error. (but works fine when we do the same filter using the UI)

* Describe the bug

when I use $in inside $or in ctx.request, it throws error. (but works fine when we do the same filter using the UI)

* Environment

  • NocoBase version: v2.2.35
  • Database type and version: PostgresSQL 18
  • OS: Ubuntu
  • Deployment Methods: Docker
  • Docker image version: nocobase/nocobase:2.2

* How To Reproduce

https://al6vo1wjap21.v12.demo.nocobase.com/admin/k3bsm39m9t6/view/17bd33f7fd6

const filter = {
      $or: [
        {
          country: {
            id: {
              $empty: true
            }
          }
        },
        {
          country: {
            id: {
              $in: [362264710283265]
            }
          }
        }
      ]
    }
await ctx.request({
  url: 'customers:list',
  params: {
    filter
  }
})

Expected behavior

it should’ve returned results without error.

error: Invalid value { ‘’: ‘362264710283265’ }

Thanks for the demo link. I opened it and reproduced the failure there.

Your filter itself is valid; the problem appears when the request is serialized. ctx.request sends params.filter as a nested object, and the client serializes arrays without indexes. When the API parses the query back, $in ends up as an object instead of an array, and the database layer reports Invalid value { '[]': '362264710283265' }. On your demo the same request returns HTTP 500 with exactly that message.

The UI is fine because table blocks send filter already JSON-stringified, so the array structure survives.

Fix for your JS block: stringify the filter yourself.

const filter = {
  $or: [
    { country: { id: { $empty: true } } },
    { country: { id: { $in: [362264710283265] } } },
  ],
};

const { data } = await ctx.request({
  url: 'customers:list',
  params: { filter: JSON.stringify(filter) },
});

I ran that form against your demo and it returned the 8 expected customers. The FlowEngine resource API also stringifies filters for you: ctx.api.resource('customers').list({ filter }).

Two notes: changing the array format alone is not enough, because deeply nested keys are also truncated during parsing, so keep the JSON-string form.

1 Like

thank you