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

Prevents the In operator from crashing when called with empty parameters #4865

Conversation

0xClpz
Copy link

@0xClpz 0xClpz commented Oct 6, 2019

The In() operator crashes if the array passed in parameters is empty, this makes it painful to work with dynamic data for the in operator.

This PR fixes that.

@pleerock
Copy link
Member

pleerock commented Oct 7, 2019

this way database will return all rows and that might be unexpected. not sure what is the best design choose here:

  • return nothing if empty array was passed
  • throw an error if empty array was passed
  • ignore condition and return all without matching - the way you did it

I'm not sure last approach is right - maybe we should return nothing in the case if empty array was passed.

@0xClpz
Copy link
Author

0xClpz commented Oct 8, 2019

Ohh nice catch! I think it should indeed return nothing if an empty array is passed! Can you point me in the right direction to implement that? Thanks!

@pleerock
Copy link
Member

If it should return nothing then we can do something like if its empty then apply IS NULL to this property. But I'm not sure we should do it.

We should think what we would like this to lead to:

           {
                where: {
                    uuid: In([])
                }
            }
  • give us all users?
  • give us users where uuid is null?

What is the point to do second? Doing uuid IS NULL seems odd in this case, isn't it?

I need some opinions here @Kononnable @vlapo

@0xClpz
Copy link
Author

0xClpz commented Oct 14, 2019

Mmhh I don't know if IS NULL is the right solution, couldn't that return values that you do not expect?

@bogdan
Copy link
Contributor

bogdan commented Oct 15, 2019

Other ORMs return nothing in this case by adding where 1 != 1 into the where condition to make sure it is really nothing.

@0xClpz
Copy link
Author

0xClpz commented Oct 27, 2019

Other ORMs return nothing in this case by adding where 1 != 1 into the where condition to make sure it is really nothing.

Just implemented that in my PR, i guess that's what makes the most sense

imnotjames added a commit that referenced this pull request Oct 15, 2020
we were supporting an empty `IN` clause for MySQL and Oracle
and this updates the handling to be for all other dialects as well
by making the "empty" clause be `0=1`

Closes #4865
fixes #2195
zaro pushed a commit to zaro/typeorm that referenced this pull request Jan 12, 2021
we were supporting an empty `IN` clause for MySQL and Oracle
and this updates the handling to be for all other dialects as well
by making the "empty" clause be `0=1`

Closes typeorm#4865
fixes typeorm#2195
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.

None yet

3 participants