Skip to content

Filtering with $null does not work on relational or media fields. #12225

@kocerb

Description

@kocerb

Bug Report

Describe the bug

When try to filter by a relational field or media type field is null or not Strapi throws error: Only $and, $or and $not can by used as root level operators. Found $null.

Steps to reproduce the behavior

1-) Create a collection type (let's say foo) that contains a relation with another collection type (let's say bar)
(or alternatively Create a collection type (let say foo) that contains a media type field (let's say bar))
2-) Send a GET request to the /foos?populate=*&filters[bar][$null]=true
3-) API returns 500 Internal Server Error and Strapi console logs the following message:

Only $and, $or and $not can by used as root level operators. Found $null.

Expected behavior

On the earlier versions of Strapi (v3) there was support to filter by a relational field is null or not with a similiar query.

System

Node.js version: v14.18.2
NPM version: v6.14.15
Strapi version: tried from v4.0.0 to v4.0.4
Database: Postgresql 10
Operating system: macOS v11.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bugissue: enhancementIssue suggesting an enhancement to an existing featureseverity: highIf it breaks the basic use of the productsource: core:databaseSource is core/database packagestatus: confirmedConfirmed by a Strapi Team member or multiple community members

    Type

    No type

    Projects

    Status

    Archive

    Status

    Fixed/Shipped

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions