Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_empty and _nempty filter in Joi Schema don't align with filters used for database querying #22277

Open
hanneskuettner opened this issue Apr 22, 2024 · 0 comments

Comments

@hanneskuettner
Copy link
Contributor

Describe the Bug

As per our documentation the _empty and _nempty filter operators work as "Is [not] empty (null or falsy)".

In applyQuery we implement it as == null || == ''. So either null or an empty string.

if ((operator === '_empty' && compareValue !== false) || (operator === '_nempty' && compareValue === false)) {
dbQuery[logical].andWhere((query) => {
query.whereNull(key).orWhere(key, '=', '');
});
}
if ((operator === '_nempty' && compareValue !== false) || (operator === '_empty' && compareValue === false)) {
dbQuery[logical].andWhere((query) => {
query.whereNotNull(key).andWhere(key, '!=', '');
});
}

In generateJoi it is only implemented as == ''

if (operator === '_empty') {
schema[key] = getAnySchema().valid('');
}
if (operator === '_nempty') {
schema[key] = getAnySchema().invalid('');
}

This can lead to unexpected results, for example when setting up access control and comparing it so API filter results or different outcomes when performing item creation vs item retrieval.
Or even for item creating vs querying, since for creating and updating the Joi schema is used for validation, for querying the database filters.

To Reproduce

.

Directus Version

v10.10.7

Hosting Strategy

Self-Hosted (Docker Image)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🆕 Needs Triage
Development

No branches or pull requests

1 participant