Query is not returning proper results, when querying for empty references array

I have…

  • Read the following guideline: Troubleshooting and Support | Squidex. I understand that my support request might get deleted if I do not follow the guideline.
  • Used code blocks with ``` to format my code examples like JSON or logs properly.

I’m submitting a…

  • Regression (a behavior that stopped working in a new release)
  • Bug report
  • Performance issue
  • Documentation issue or request

Current behavior

If you have a schema with references field and create Object B pointing to Object A in this schema, then when you remove Object A, and query for all objects in schema which have empty references field, Object B will not be returned. I believe this happens because references field in Object B after removal of Object A is not null, but is an empty array - [], and squidex when operating query like empty(data/parentId/iv) is only querying for null values.

Expected behavior

I expect query for empty references array to return all objects, which have either null or [] references field. Other solution might be to set reference field to null when last referenced object is being removed.

Minimal reproduction of the problem

  1. Create schema with references field
  2. Create Object A in this schema
  3. Create Object B in same schema, pointing to Object A in references field
  4. Remove Object A
  5. Query for objects with empty references field, you shouldn’t receive Object B
http://localhost:80/api/content/{app}/{schema}?$filter=empty(data/parentId/iv)

Environment

App Name: default

  • Self hosted with docker
  • Self hosted with IIS
  • Self hosted with other version
  • Cloud version

Version: 7.15.0.0

The empty filter actually works like your suggestion: squidex/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/Queries/FilterVisitor.cs at adf0711bc2e61be111a051e03e59828f9698fe01 · Squidex/squidex · GitHub

Seems to be somethin else.

I have tested it and it works fine for me.

That is wierd, because i can still see that issue in both UI and from API calls. Also in your code i haven’t seen the comparison to empty array.

Here is example of references value when it is manually unset in the UI:

(will place it in next message, beacause new users can only paste 1 image in post)

And here the value of the same field when you delete parent object:

So when i execute query for this field to be empty, in second case value is not returned (as i’ve seen from the code, because there is no comparison to empty array, only null, false, 0 and empty string).

Example of request:

curl  -X GET \
  'http://localhost:80/api/content/default/testschema2?$filter=empty(data%2FparentId%2Fiv)' \
  --header 'Authorization: Bearer example-token-value'

The query uses the size operator for arrays. This seems to work locally, but I will try it again.