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

accessible_by bug after upgrading to rails 5.2 #478

Closed
lizzyaustad opened this issue Jan 26, 2018 · 8 comments · Fixed by rubyforgood/Flaredown#484
Closed

accessible_by bug after upgrading to rails 5.2 #478

lizzyaustad opened this issue Jan 26, 2018 · 8 comments · Fixed by rubyforgood/Flaredown#484

Comments

@lizzyaustad
Copy link
Contributor

lizzyaustad commented Jan 26, 2018

Steps to reproduce

  1. Upgrade to Rails 5.2 (currently at '5.2.0.beta2' version)
  2. Call accessible_by (or run active_record_adapter spec)

Gist: https://gist.github.com/lizzyaustad/4096f904f6d0b409462f7fdf7c60b65e

Expected behavior

Should be able to use accessible_by without raising exception

Actual behavior

An exception is raised:

ActiveRecord::StatementInvalid: SQLite3::MismatchException: datatype mismatch: SELECT  "articles".* FROM "articles" WHERE ((secret='t') OR ("articles"."published" = ?)) LIMIT ?

This is due to a change in Rails 5.2 that creates a BindParam node for the attribute. The BindParam node moves the intended value for the query under .value_before_type_cast instead of the previous .val it had before with the Casted node, resulting in a query like the one above, where the ? value does not get filled in: ("articles"."published" = ?)) LIMIT ?

Possible fixes

If this error persists with the official release of Rails 5.2, this change in active_record_4_adapter.rb could fix the issue on the cancancan side.

System configuration

Rails version: 5.2.0.beta2

Ruby version: 2.3.0

CanCanCan version 2.0.0

lizzyaustad added a commit to lizzyaustad/cancancan that referenced this issue Jan 29, 2018
@kylekeesling
Copy link

I'm seeing what seems to be the same error, using postgresql

@jeffpereira
Copy link

The error is based on the pieces of code that turn ActiveRecord queries into SQL, so the issue will exist on any SQL based DB. @kylekeesling

@kylekeesling
Copy link

Ok good to know. I just wanted to make sure I provided the right context for what I was seeing.

@andrewculver
Copy link
Contributor

@lizzyaustad Thanks very much for your for your PR. It allowed us to move forward using Rails 5.2.0-rc1 in the meantime.

@toao
Copy link

toao commented Apr 13, 2018

I'm seeing deprecation warnings apparently triggered by accessible_by: DEPRECATION WARNING: expand_hash_conditions_for_aggregates is deprecated and will be removed from Rails 6.0 with rails 5.2

@coorasse coorasse reopened this Apr 15, 2018
@coorasse
Copy link
Member

coorasse commented Sep 2, 2018

This issue should be solved with the latest version of CanCanCan

@coorasse coorasse closed this as completed Sep 2, 2018
@capjuancode
Copy link

Was this resolve and from what version, I currently have it on 1.17.0

@raoulalwani
Copy link

@capjuancode you probably already figured this out, but for one app we just upgraded on, we went from 1.15 to 2.3.0. Leaving this here for anyone else who might stumble across it.

For reference, this issue arose when upgrading to Rails 5.2

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

Successfully merging a pull request may close this issue.

8 participants