JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Error "undefined method 'where' for" error on ActiveModel based resource

Open
#1,467 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

We just tried moving from v0.9.12 to v0.10.7 (and even tried with lower 10.x versions) and now our ActiveModel based models no longer work via resources. We now get a Internal Server Error: undefined method 'where' for error. Not sure what to do. Any help is greatly appreciated.

2025-02-24 20:22:55.712035 E [16:puma srv tp 004 acts_as_resource_controller.rb:289] {uuid: 0f40c8d0c138f0444cf4be9f7a8ec7ae} Rails -- Internal Server Error: undefined method `where' for AuthorizeV2:Class /app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/active_relation_resource.rb:877:in `apply_filter'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/active_relation_resource.rb:846:in `block in apply_filters'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/active_relation_resource.rb:845:in `each'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/active_relation_resource.rb:845:in `apply_filters'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/active_relation_resource.rb:777:in `filter_records'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/active_relation_resource.rb:707:in `apply_request_settings_to_records'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/active_relation_resource.rb:107:in `find_fragments'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/processor.rb:412:in `find_resource_id_tree'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/processor.rb:372:in `find_resource_set'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/processor.rb:245:in `create_resource'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/processor.rb:34:in `block (2 levels) in process'
/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.7/lib/active_support/callbacks.rb:107:in `run_callbacks'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/processor.rb:33:in `block in process'
/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.7/lib/active_support/callbacks.rb:99:in `run_callbacks'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/processor.rb:32:in `process'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/operation.rb:12:in `process'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/acts_as_resource_controller.rb:140:in `process_operation'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/acts_as_resource_controller.rb:110:in `block (3 levels) in process_request'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/request_parser.rb:32:in `each'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/acts_as_resource_controller.rb:97:in `block (2 levels) in process_request'
/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.7/lib/active_support/callbacks.rb:99:in `run_callbacks'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/acts_as_resource_controller.rb:96:in `block in process_request'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/acts_as_resource_controller.rb:127:in `block (2 levels) in process_operations'
/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.7/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.7/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.7/lib/active_record/connection_adapters/abstract/database_statements.rb:316:in `transaction'
/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.7/lib/active_record/transactions.rb:209:in `transaction'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/acts_as_resource_controller.rb:126:in `block in process_operations'
/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.7/lib/active_support/callbacks.rb:99:in `run_callbacks'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/acts_as_resource_controller.rb:125:in `process_operations'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/acts_as_resource_controller.rb:95:in `process_request'
/app/vendor/bundle/ruby/3.2.0/gems/jsonapi-resources-0.10.7/lib/jsonapi/acts_as_resource_controller.rb:31:in `create'
/app/vendor/bundle/ruby/3.2.0/gems/actionpack-7.0.8.7/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
/app/vendor/bundle/ruby/3.2.0/gems/actionpack-7.0.8.7/lib/abstract_controller/base.rb:215:in `process_action'
/app/vendor/bundle/ruby/3.2.0/gems/actionpack-7.0.8.7/lib/action_controller/metal/rendering.rb:165:in `process_action'
/app/vendor/bundle/ruby/3.2.0/gems/actionpack-7.0.8.7/lib/abstract_controller/callbacks.rb:234:in `block in process_action'
/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.7/lib/active_support/callbacks.rb:118:in `block in run_callbacks'

resource:

class AuthorizeResource < JSONAPI::Resource
  model_name 'AuthorizeV2'
  model_hint model: AuthorizeV2, resource: :authorize

  attributes [LIST OF ATTRIBUTES]

end

model:

class AuthorizeV2
  include ActiveModel::Model

  attr_accessor [LIST OF ATTRIBUTES]
end

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start with jsonapi/active_relation_resource.rb, especially apply_filter and apply_filters, using the reported JSONAPI Resources 0.9.12-to-0.10.7 change and ActiveModel-only AuthorizeV2 example to reproduce the failure. Compare the behavior with an ActiveRecord-backed resource and define a regression test that passes once filtering an ActiveModel resource no longer raises the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.