#28288·directus

`_some` / `_none` on an o2m is silently ignored when it contains `_and` / `_or` or more than one field

Author: rizz360Created Sep 24, 2026Updated Sep 29, 2026
LabelsBugQueryingCoreMed ImpactLow Reach

Describe the Bug

When _some (or _none) on an o2m field has an _and / _or inside it, or more than one field, the filter gets dropped and every row comes back. No error, nothing in the logs. _some with a single field works fine.

Leaving _some out and putting the _and straight on the o2m field does work, and all conditions are checked against the same related item, so that's my workaround for now. _none has no equivalent though, so "no related item where A and B" can't be expressed at all right now.

We noticed because a "currently enrolled" filter on our students (enrollment: { _some: { _and: [start <= now, end null or >= now] } }) was returning every student, 51 instead of 32.

Might be related to #25403 / #27704, but that's about _some further down the tree. Here it's directly on a top level o2m alias, and nothing gets rejected, it's just silently ignored.

To Reproduce

Clean container, sqlite. parent has an o2m alias children, child has label (string), n (integer) and parent (m2o).

  • P1: child (a, 1)
  • P2: children (a, 2) and (b, 1)
  • P3: child (c, 3)

GET /items/parent?fields=name&filter=...:

filter                                                          expected   got
children: { _some: { label: { _eq: "a" } } }                    P1 P2      P1 P2
children: { _some: { _and: [{ label: { _eq: "a" } }] } }        P1 P2      P1 P2 P3
children: { _some: { label: { _eq: "a" }, n: { _eq: 1 } } }     P1         P1 P2 P3
children: { _some: { _and: [{ label: a }, { n: 1 }] } }         P1         P1 P2 P3
children: { _none: { _and: [{ label: a }, { n: 1 }] } }         P2 P3      P1 P2 P3
children: { _and: [{ label: a }, { n: 1 }] }   (no _some)       P1         P1

Same results on 11.17.4 and 12.4.1. Originally hit it on Postgres.

Script (python, stdlib only)
bash
docker run -d --name dx-repro -p 8099:8055 -e SECRET=x -e DB_CLIENT=sqlite3 \
  -e DB_FILENAME=/tmp/db.sqlite -e [email protected] -e ADMIN_PASSWORD=pw \
  directus/directus:12.4.1
python3 repro.py http://localhost:8099
python
import json, sys, time, urllib.parse, urllib.request

base = sys.argv[1]

def call(method, path, body=None, tok=None):
    headers = {"Content-Type": "application/json"}
    if tok:
        headers["Authorization"] = "Bearer " + tok
    data = json.dumps(body).encode() if body is not None else None
    req = urllib.request.Request(base + path, method=method, data=data, headers=headers)
    return json.load(urllib.request.urlopen(req))

for _ in range(90):
    try:
        urllib.request.urlopen(base + "/server/health")
        break
    except Exception:
        time.sleep(2)

tok = call("POST", "/auth/login", {"email": "[email protected]", "password": "pw"})["data"]["access_token"]
pk = {"field": "id", "type": "integer", "schema": {"is_primary_key": True, "has_auto_increment": True}}
call("POST", "/collections", {"collection": "parent", "schema": {}, "fields": [pk, {"field": "name", "type": "string"}]}, tok)
call("POST", "/collections", {"collection": "child", "schema": {}, "fields": [
    pk, {"field": "label", "type": "string"}, {"field": "n", "type": "integer"}, {"field": "parent", "type": "integer"}]}, tok)
call("POST", "/relations", {"collection": "child", "field": "parent", "related_collection": "parent",
                            "meta": {"one_field": "children"}}, tok)
call("POST", "/fields/parent", {"field": "children", "type": "alias", "meta": {"special": ["o2m"]}}, tok)
call("POST", "/items/parent", [
    {"name": "P1", "children": [{"label": "a", "n": 1}]},
    {"name": "P2", "children": [{"label": "a", "n": 2}, {"label": "b", "n": 1}]},
    {"name": "P3", "children": [{"label": "c", "n": 3}]},
], tok)

a, n1 = {"label": {"_eq": "a"}}, {"n": {"_eq": 1}}
tests = {
    "_some label": {"children": {"_some": a}},
    "_some _and[label]": {"children": {"_some": {"_and": [a]}}},
    "_some label + n": {"children": {"_some": {**a, **n1}}},
    "_some _and[label, n]": {"children": {"_some": {"_and": [a, n1]}}},
    "_none _and[label, n]": {"children": {"_none": {"_and": [a, n1]}}},
    "no _some, _and[label, n]": {"children": {"_and": [a, n1]}},
}
for name, f in tests.items():
    q = urllib.parse.urlencode({"filter": json.dumps(f), "fields": "name"})
    print(name, [x["name"] for x in call("GET", "/items/parent?" + q, tok=tok)["data"]])

Directus Version

11.17.4, also checked on 12.4.1

Hosting Strategy

Self-Hosted (Docker Image)

Database

PostgreSQL 13.8 (repro above on sqlite)