Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Issues
  • #1570
Closed
Open
Issue created Mar 14, 2020 by Sébastien Dubois@sedubois

0.13.0 regressions with nested forms (and polymorphic relations?)

  • What were you trying to do?

Upgrading to Administrate 0.13.0.

  • What did you end up with (logs, or, even better, example apps are great!)?

I use administrate 0.12.0 and administrate-field-nested_has_many 1.2.0. With administrate 0.13.0, the gem now throws this error:

     ActionView::Template::Error:
       undefined method `school' for #<ActiveRecord::Associations::CollectionProxy []>
     # ./lib/administrate/field/nested_has_many.rb:23:in `nested_fields'
     # ./lib/administrate/field/nested_has_many.rb:29:in `nested_fields_for_builder'
     # ./app/views/fields/nested_has_many/_fields.html.erb:2:in `___sers_sdubois__epos_administrate_field_nested_has_many_app_views_fields_nested_has_many__fields_html_erb__2516551389881800165_70257731404460'
     # ./app/views/fields/nested_has_many/_form.html.erb:14:in `___sers_sdubois__epos_administrate_field_nested_has_many_app_views_fields_nested_has_many__form_html_erb__1295690092843922213_70257781048500'
     # ./spec/features/has_many_spec.rb:23:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   undefined method `school' for #<ActiveRecord::Associations::CollectionProxy []>
     #   ./lib/administrate/field/nested_has_many.rb:23:in `nested_fields'

When loading the school form in the gem's dummy app, the error above is triggered when building a nested Student's school field of type BelongsTo. It can be reproduced by updating the gem's administrate dependency to 0.13.0 and running the tests.

It appears a regression due to rescue NameError which was removed in https://github.com/thoughtbot/administrate/pull/920/files#diff-a4a632998186059ef606368d710ac173L36.

Administrate::Page::Form#attributes calls Administrate::Page::Base#attribute_field then get_attribute_value executes resource.public_send(attribute_name) with resource=Foo::Student::ActiveRecord::Associations::CollectionProxy and attribute_name="school". This throws a NoMethodError, which is a descendent of NameError.

The exception is no longer rescued in Administrate 0.13.0 for reasons explained in https://github.com/thoughtbot/administrate/issues/480. The rescue clause had previously been added in this commit titled "Add support for polymorphic relationships". So potentially there could also be a regression with the handling of polymorphic relations (I can't say as I haven't used them yet)?

I observe issues in my own app when loading the form for Posts which has a NestedHasMany translations association which themselves have a locale field of a type based on CollectionSelect (adapted for my own needs). This is currently blocking me from upgrading to Administrate 0.13.0.

As the problem potentially occurs in different kinds of fields I'm opening the issue on this repo and not e.g. on the NestedHasMany repo.

@pablobm would you have any idea how to ensure forms with nested fields keep working while avoiding silent errors with incorrect association names?

  • What versions are you running?
    • Rails 6.0.2.1
    • administrate 0.13.0
    • administrate-field-nested_has_many 1.2.0
Assignee
Assign to
Time tracking