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

"Unsupported argument type: NilClass. Construct an Arel node instead." when using where(polymorphic_association: []) #41105

Closed
jalyna opened this issue Jan 13, 2021 · 2 comments · Fixed by #41063

Comments

@jalyna
Copy link

jalyna commented Jan 13, 2021

First of all thanks for the great work! I hope I thoroughly checked all created issues so this is no duplicate.

Steps to reproduce

I created a minimal repository with rails new :

See minimal changes in this commit:
jalyna/demo-polymorphic-rails61-issue@928fd7b

Basically this test

assert_nil Subscription.find_by(plan: []) # plan is a polymorphic belongs_to association

fails with 6.1.x, resulting in: Unsupported argument type: NilClass. Construct an Arel node instead.

I also created a branch using 6.0.3 where the test passes. https://github.com/jalyna/demo-polymorphic-rails61-issue/tree/rails60

This test will pass though (no rows within public_plans):

assert_nil Subscription.find_by(plan: PublicPlan.all)

The workaround I'm currently using in my projects is to not trigger a query when the array is empty.

Expected behavior

Subscription.find_by(plan: []) # plan is a polymorphic belongs_to association

should return nil

Actual behavior

Subscription.find_by(plan: []) # plan is a polymorphic belongs_to association

raises: Unsupported argument type: NilClass. Construct an Arel node instead.

System configuration

Rails version: 6.1.0 & 6.1.1

Ruby version: 2.7.1

@dbussink
Copy link
Contributor

dbussink commented Jan 13, 2021

This was fixed with #41063, the same issue was identified in #40951 (comment). There's no release yet though afaik that includes this fix.

@jalyna
Copy link
Author

jalyna commented Jan 13, 2021

@dbussink thank you!

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 a pull request may close this issue.

3 participants