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

fix(db-postgres): querying with in: [] returns empty result #11011

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yunus-emre-zengin
Copy link

@yunus-emre-zengin yunus-emre-zengin commented Feb 6, 2025

There was an issue with relational databases where, when an empty array was used as a value for the IN operator, the constraint was being ignored. Fixes #10788

I investigated this issue and found that, in the past, Drizzle's inArray operator would throw an error when it received an empty array. Because of this behavior, the Payload server would crash when handling queries with in: []. To address this, the following commit was made: c4ac341.

However, this approach resulted in the constraint being ignored, which is not the ideal behavior. The Drizzle community discussed the expected behavior of the inArray operator (see: drizzle-team/drizzle-orm#1295), and the team decided to modify it to accept empty arrays instead of throwing an error.

With this change, simply removing the unnecessary check resolves the issue.

After making this fix, one of the tests failed because it was using the not_in operator. I also updated the test to reflect the new behavior.

@yunus-emre-zengin yunus-emre-zengin changed the title fix(db-postgres): querying with in: [] returns empty result #10788 fix(db-postgres): querying with in: [] returns empty result Feb 6, 2025
@yunus-emre-zengin
Copy link
Author

@r1tsuu I am mentioning you because the issue I was trying to solve is assigned to you and you are an active team member in the repo

I am not experienced with pull requests, did I miss something here? Several days passed but nothing happened

JarrodMFlesch added a commit that referenced this pull request Feb 10, 2025
### What?
If you had multiple operator constraints on a single field, the last one
defined would be the only one used.

Example:
```ts
where: {
  id: {
    in: [doc2.id],
    not_in: [], // <-- only respected this operator constraint
  },
}
```

and
```ts
where: {
  id: {
    not_in: [],
    in: [doc2.id], // <-- only respected this operator constraint
  },
}
```

They would yield different results.

### Why?
The results were not merged into an `$and` query inside parseParams.

### How?
Merges the results within an `$and` constraint.

Fixes #10944

Supersedes #11011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected Behavior: in Operator Returns Entire Collection with Empty Array
1 participant