Open ctm opened 8 years ago
I have faced with the same issue today. I do not understand why do we need to use .all in
@controller.policy_scope(abstract_model.model.all)
What about simple fix the issue with removing .all. That is all!
def query(_action, abstract_model)
@controller.policy_scope(abstract_model.model)
rescue ::Pundit::NotDefinedError
abstract_model.model.all
end
@ctm any objections why we can not go with that and cancel your pull request?
extensions/pundit/authorization_adapter.rb
contains this code:but at least in
pundit 1.1.0
, the construction ofPundit::NotDefinedError
callsinspect
on the scope. This has the effect of retrieving every single row from the database table in question. We ran into this with a table that has over a million rows.I have monkey-patched our application to get around this. I have also created a PR which has a spec that fails with the existing code and works with my patch. I'm submitting this issue before the PR so my commit can reference this issue.