Error "undefined method 'where' for" error on ActiveModel based resource
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
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.
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
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JSONAPI-Resources/jsonapi-resources
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 3/5 1-2 days Newbie friendliness 50/100
JSONAPI-Resources/jsonapi-resources#1488 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
JSONAPI-Resources/jsonapi-resources#1479 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
JSONAPI-Resources/jsonapi-resources#1477 · 3 comments · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
All issues in JSONAPI-Resources/jsonapi-resources
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
TheOdinProject/curriculum#31423 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
oxidize-rb/rb-sys#807 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day