Expose with :if and lambda stopped working on Ruby 2.4.1

Open
#269 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
api

Research direction

Start at entity.rb:477 and inspect how exec_with_object invokes the :if lambda under Ruby 2.4.1, comparing it with Ruby 2.4.0 using the minimal expose :anything, if: -> { true } reproducer. Done means the lambda-based :if expose works without the wrong-number-of-arguments error.

Written by the indexing model from the issue text.

Description

bug?

I updated to Ruby 2.4.1 and grape-entity started complaining about using a lambda with :if.

This worked perfectly on Ruby 2.4.0, grape 0.19.2 and grape-entity 0.6.1:

expose :context_company_id, if: -> { company_context? }

It doesn't help if I reduce the problem, this is still broken:

expose :anything, if: -> { true }

Using Ruby 2.4.1 the following error message appears instead:
caught error of type ArgumentError in after callback inside Grape::Middleware::Formatter : wrong number of arguments (given 2, expected 0)

I tried to attach a debugger at entity.rb:477, but I don't know how to figure out options. If I try to inspect it, it'll throw the same error. If I print it, it's very long and I have no idea what to look for.

    def exec_with_object(options, &block)
      debugger
      instance_exec(object, options, &block)
    end
(byebug) pp options.inspect
*** ArgumentError Exception: wrong number of arguments (given 2, expected 0)

Any ideas?

Dominant language
Ruby
Stars
729
Forks
154
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby-grape/grape-entity

All issues in ruby-grape/grape-entity

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.