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

Controller name inflection failing with v5.0.1.rc1 #27297

Closed
aried3r opened this issue Dec 7, 2016 · 4 comments
Closed

Controller name inflection failing with v5.0.1.rc1 #27297

aried3r opened this issue Dec 7, 2016 · 4 comments
Assignees
Milestone

Comments

@aried3r
Copy link
Contributor

aried3r commented Dec 7, 2016

Steps to reproduce

I was sadly unable to create a minimal, complete, and verifiable example from our codebase, but basically at work we have a class ProjectsController < ApplicationController and from what I can tell, almost all tests that touch it fail using v5.0.1.rc1.

I'll try to find a short executable example. Meanwhile I was able to pinpoint the commit using git bisect.

ba66ed094a5007e0746976781729d5d9e71b8cc9 is the first bad commit
commit ba66ed094a5007e0746976781729d5d9e71b8cc9
Author: Matthew Draper <matthew@trebex.net>
Date:   Fri Nov 25 00:48:00 2016 +1030

    Merge pull request #26718 from domcleal/5-0-stable-ids-writer-exception

    Restore RecordNotFound when *_ids= can't find records by ID

:040000 040000 fe2be16d3e4dbd1aa10d4e05db58c4a6d56d425f 74ff037d2109bea49fba4c5c9828a44e9688eb5c M	activerecord

But I'll try to bisect once more later in the afternoon to verify.

To me it seems that before it resolved correctly to ProjectsController but in v5.0.1.rc1 it resolves to Project::Controller (unless of course, this is used internally somewhere).

Expected behavior

Testcases should work and find the ProjectsController constant.

Actual behavior

Running a spec which accesses the controller, using --backtrace results in the following error:

NameError:
uninitialized constant Project::Controller
# ~/Development/rails/activerecord/lib/active_record/inheritance.rb:152:in `compute_type'
# ~/Development/rails/activerecord/lib/active_record/reflection.rb:354:in `compute_class'
# ~/Development/rails/activerecord/lib/active_record/reflection.rb:350:in `klass'
# ~/Development/rails/activerecord/lib/active_record/reflection.rb:402:in `association_primary_key_type'
# ~/Development/rails/activerecord/lib/active_record/reflection.rb:988:in `association_primary_key_type'
# ~/Development/rails/activerecord/lib/active_record/associations/collection_association.rb:72:in `ids_writer'
# ~/Development/rails/activerecord/lib/active_record/associations/builder/collection_association.rb:66:in `controller_ids='
# ~/Development/rails/activemodel/lib/active_model/attribute_assignment.rb:46:in `public_send'
# ~/Development/rails/activemodel/lib/active_model/attribute_assignment.rb:46:in `_assign_attribute'
# ~/Development/rails/activemodel/lib/active_model/attribute_assignment.rb:40:in `block in _assign_attributes'
# ~/Development/rails/activemodel/lib/active_model/attribute_assignment.rb:39:in `each'
# ~/Development/rails/activemodel/lib/active_model/attribute_assignment.rb:39:in `_assign_attributes'
# ~/Development/rails/activerecord/lib/active_record/attribute_assignment.rb:26:in `_assign_attributes'
# ~/Development/rails/activemodel/lib/active_model/attribute_assignment.rb:33:in `assign_attributes'
# ~/Development/rails/activerecord/lib/active_record/persistence.rb:266:in `block in update'
# ~/Development/rails/activerecord/lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'
# ~/Development/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
# ~/Development/rails/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
# ~/Development/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
# ~/Development/rails/activerecord/lib/active_record/transactions.rb:211:in `transaction'
# ~/Development/rails/activerecord/lib/active_record/transactions.rb:392:in `with_transaction_returning_status'
# ~/Development/rails/activerecord/lib/active_record/persistence.rb:265:in `update'
# ./app/controllers/projects_controller.rb:107:in `update'
# ~/Development/rails/actionpack/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
# ~/Development/rails/actionpack/lib/abstract_controller/base.rb:188:in `process_action'
# ~/Development/rails/actionpack/lib/action_controller/metal/rendering.rb:30:in `process_action'
# ~/Development/rails/actionpack/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
# ~/Development/rails/activesupport/lib/active_support/callbacks.rb:126:in `call'
# ~/Development/rails/activesupport/lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
# ~/Development/rails/activesupport/lib/active_support/callbacks.rb:455:in `call'
# ~/Development/rails/activesupport/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
# ~/Development/rails/activesupport/lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
# ~/Development/rails/activesupport/lib/active_support/callbacks.rb:90:in `run_callbacks'
# ~/Development/rails/actionpack/lib/abstract_controller/callbacks.rb:19:in `process_action'
# ~/Development/rails/actionpack/lib/action_controller/metal/rescue.rb:20:in `process_action'
# ~/Development/rails/actionpack/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
# ~/Development/rails/activesupport/lib/active_support/notifications.rb:164:in `block in instrument'
# ~/Development/rails/activesupport/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
# ~/Development/rails/activesupport/lib/active_support/notifications.rb:164:in `instrument'
# ~/Development/rails/actionpack/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# ~/Development/rails/actionpack/lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
# ~/Development/rails/activerecord/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
# ~/Development/rails/actionpack/lib/abstract_controller/base.rb:126:in `process'
# ~/Development/rails/actionview/lib/action_view/rendering.rb:30:in `process'
# ~/Development/rails/actionpack/lib/action_controller/metal.rb:190:in `dispatch'
# ~/Development/rails/actionpack/lib/action_controller/test_case.rb:547:in `process'
# ~/Development/rails/actionpack/lib/action_controller/test_case.rb:646:in `process_with_kwargs'
# ~/Development/rails/actionpack/lib/action_controller/test_case.rb:409:in `put'
# ./spec/controllers/projects_controller_spec.rb:361:in `block (6 levels) in <top (required)>'
# ./spec/controllers/projects_controller_spec.rb:361:in `block (5 levels) in <top (required)>'

System configuration

Rails version:
v5.0.1.rc1
Ruby version:
2.3.1

@matthewd
Copy link
Member

matthewd commented Dec 7, 2016

# ~/Development/rails/activerecord/lib/active_record/associations/builder/collection_association.rb:66:in `controller_ids='

It seems more likely to be related to this controller_ids= call... perhaps implying you have a has_many :controllers on your Project model?

Hopefully that's enough of a clue to help isolate it. If not, can you just show that association's definition?

@matthewd matthewd added this to the 5.0.1 milestone Dec 7, 2016
@matthewd matthewd self-assigned this Dec 7, 2016
@aried3r
Copy link
Contributor Author

aried3r commented Dec 7, 2016

perhaps implying you have a has_many :controllers on your Project model?

Hah! Oh my, that's indeed the case. I completely forgot about that. It's an older code, Sir, but it checks out.

Thanks! But I'm not sure how to proceed here, is controller reserved somehow now?

  # project.rb
  has_many :controller_relationships,
           -> { where role: :CONTROLLER },
           class_name: 'ProjectUserRole',
           dependent: :destroy
  has_many :controllers,
           through: :controller_relationships,
           source: :user,

@matthewd
Copy link
Member

matthewd commented Dec 7, 2016

I think this is a bug in how ba66ed0 / #26718 interacts with has_many :through + explicit class_name and/or source... I imagine it would have the same problem with any other, less suspiciously-similar-to-other-parts-of-Rails, name too.

@matthewd
Copy link
Member

matthewd commented Dec 8, 2016

Fixed by 847e9dd; backported as d5f0758

@matthewd matthewd closed this as completed Dec 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants