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

How to debug ArgumentError - too few arguments in lib/representable/serializer.rb:6 #202

Open
Envek opened this issue Nov 8, 2016 · 1 comment

Comments

@Envek
Copy link

Envek commented Nov 8, 2016

My app is failing there with too few arguments exception raised from representable (I don't use representable directly): https://github.com/apotonick/representable/blob/830f2ceb7feddef1f181952d878f22623c4a431b/lib/representable/serializer.rb#L6

I have a Trailblazer enabled Rails application with next Contract in it:

module Admin
  module DatasetStructure::Contract
    class Create < Reform::Form
      property :version
      property :dataset_id

      collection :fields, prepopulator: :prepopulate_dataset_fields!, populator: :populate_dataset_fields! do
        property :name
        property :description
        property :format
        property :position
        property :parent_id

        validates :name, :description, :format, presence: true

        # For Cocoon gem to work
        delegate :new_record?, to: :model
        delegate :marked_for_destruction?, to: :model
        delegate :_destroy, to: :model
      end

      validates :dataset_id, :version, presence: true
 
      # populator and prepopulator methods omitted for brevity
    end
  end
end

Which is used in operation:

module Admin
  class DatasetStructure::Create < Trailblazer::Operation
    include Model
    include Trailblazer::Operation::Policy

    model ::DatasetStructure, :create
    policy DatasetStructure::Policy, :create?
    contract DatasetStructure::Contract::Create

    def setup_model!(params)
      @model.dataset = params[:dataset] || Dataset.from_param(params[:dataset_id])
    end

    def process(params)
      ::DatasetStructure.transaction do
        validate(params[:dataset_structure]) do
          contract.save
        end
      end
    end
  end
end

And model:

class DatasetStructure < ApplicationRecord
  belongs_to :dataset, inverse_of: :structures
  has_many :fields,    class_name: 'DatasetField',   dependent: :destroy, inverse_of: :structure
  accepts_nested_attributes_for :fields, reject_if: :all_blank, allow_destroy: true
end

I've placed a binding.pry there (at lib/representable/serializer.rb:6), and getting next results:

# When name field is being processed the getter is a method of OpenStruct contained it:
options[:binding].getter
=> "name"
options[:binding].send(:exec_context, options)
=> #<OpenStruct name="name", description="description", format="string", position=0, parent_id=nil>
[2] pry(Representable)> method = options[:binding].send(:exec_context, options).method(options[:binding].getter)
=> #<Method: OpenStruct#name>

# But when format field is being processed one thing get different: method isn't from this OpenStruct:
options[:binding].getter
=> "format"
method = options[:binding].send(:exec_context, options).method(options[:binding].getter)
=> #<Method: OpenStruct(Kernel)#format>
# And…
method = options[:binding].send(:exec_context, options).send(options[:binding].getter)
too few arguments

Stacktrace:

ArgumentError - too few arguments:
  representable (3.0.0) lib/representable/serializer.rb:6:in `block in <module:Representable>'
  representable (3.0.0) lib/representable/pipeline.rb:18:in `evaluate'
  representable (3.0.0) lib/representable/pipeline.rb:10:in `block in call'
  representable (3.0.0) lib/representable/pipeline.rb:9:in `call'
  representable (3.0.0) lib/representable/binding.rb:32:in `compile_fragment'
  representable (3.0.0) lib/representable.rb:52:in `block in call'
  representable (3.0.0) lib/representable.rb:50:in `call'
  representable (3.0.0) lib/representable.rb:69:in `representable_map!'
  representable (3.0.0) lib/representable.rb:44:in `create_representation_with'
  representable (3.0.0) lib/representable/hash.rb:34:in `to_hash'
  disposable (0.3.2) lib/disposable/twin/sync.rb:77:in `to_nested_hash'
  reform-rails (0.1.7) lib/reform/form/active_record.rb:24:in `to_nested_hash'
  reform (2.2.1) lib/reform/validation.rb:36:in `valid?'
  reform (2.2.1) lib/reform/contract/validate.rb:18:in `validate!'
  reform (2.2.1) lib/reform/contract/validate.rb:30:in `block (2 levels) in validate_nested!'
  disposable (0.3.2) lib/disposable/twin/property_processor.rb:24:in `block in collection!'
  disposable (0.3.2) lib/disposable/twin/property_processor.rb:24:in `collection!'
  disposable (0.3.2) lib/disposable/twin/property_processor.rb:15:in `call'
  reform (2.2.1) lib/reform/contract/validate.rb:30:in `block in validate_nested!'
  disposable (0.3.2) lib/disposable/twin/definitions.rb:22:in `block in each'
  declarative (0.0.8) lib/declarative/definitions.rb:30:in `each'
  disposable (0.3.2) lib/disposable/twin/definitions.rb:16:in `each'
  reform (2.2.1) lib/reform/contract/validate.rb:28:in `validate_nested!'
  reform (2.2.1) lib/reform/contract/validate.rb:16:in `validate!'
  reform (2.2.1) lib/reform/contract/validate.rb:10:in `validate'
  reform (2.2.1) lib/reform/form/validate.rb:23:in `validate'
  trailblazer (1.1.1) lib/trailblazer/operation.rb:146:in `validate_contract'
  trailblazer (1.1.1) lib/trailblazer/operation.rb:136:in `validate'
  trailblazer (1.1.1) lib/trailblazer/operation/model.rb:36:in `validate'
  app/concepts/admin/dataset_structure/operation/create.rb:16:in `block in process'
  activerecord (5.0.0.1) lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
  activerecord (5.0.0.1) lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
  activerecord (5.0.0.1) lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
  activerecord (5.0.0.1) lib/active_record/transactions.rb:211:in `transaction'
  app/concepts/admin/dataset_structure/operation/create.rb:15:in `process'
  trailblazer (1.1.1) lib/trailblazer/operation.rb:70:in `run'
  trailblazer (1.1.1) lib/trailblazer/operation.rb:14:in `run'
  trailblazer (1.1.1) lib/trailblazer/operation/controller.rb:26:in `block in run'
  trailblazer (1.1.1) lib/trailblazer/endpoint.rb:16:in `call'
  trailblazer (1.1.1) lib/trailblazer/operation/controller.rb:61:in `operation_for!'
  trailblazer (1.1.1) lib/trailblazer/operation/controller.rb:26:in `run'
  app/controllers/admin/dataset_structures_controller.rb:10:in `create'
  actionpack (5.0.0.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
  actionpack (5.0.0.1) lib/abstract_controller/base.rb:188:in `process_action'
  actionpack (5.0.0.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
  actionpack (5.0.0.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (5.0.0.1) lib/active_support/callbacks.rb:126:in `call'
  activesupport (5.0.0.1) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
  activesupport (5.0.0.1) lib/active_support/callbacks.rb:455:in `call'
  activesupport (5.0.0.1) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
  activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
  activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
  actionpack (5.0.0.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (5.0.0.1) lib/action_controller/metal/rescue.rb:20:in `process_action'
  actionpack (5.0.0.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (5.0.0.1) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (5.0.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activesupport (5.0.0.1) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (5.0.0.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (5.0.0.1) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
  activerecord (5.0.0.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (5.0.0.1) lib/abstract_controller/base.rb:126:in `process'
  actionview (5.0.0.1) lib/action_view/rendering.rb:30:in `process'
  actionpack (5.0.0.1) lib/action_controller/metal.rb:190:in `dispatch'
  actionpack (5.0.0.1) lib/action_controller/metal.rb:262:in `dispatch'
  actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
  actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'
  actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:39:in `block in serve'
  actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:26:in `serve'
  actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:725:in `call'
  omniauth (1.3.1) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.3.1) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.3.1) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.3.1) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.3.1) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.3.1) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.3.1) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.3.1) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.3.1) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.3.1) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.3.1) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.3.1) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.3.1) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.3.1) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.3.1) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.3.1) lib/omniauth/strategy.rb:164:in `call'
  meta_request (0.4.0) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
  meta_request (0.4.0) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
  http_accept_language (2.0.5) lib/http_accept_language/middleware.rb:14:in `call'
  warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.6) lib/warden/manager.rb:34:in `call'
  rack (2.0.1) lib/rack/etag.rb:25:in `call'
  rack (2.0.1) lib/rack/conditional_get.rb:38:in `call'
  rack (2.0.1) lib/rack/head.rb:12:in `call'
  rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
  rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
  actionpack (5.0.0.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
  activerecord (5.0.0.1) lib/active_record/migration.rb:552:in `call'
  actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
  activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
  activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
  activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
  actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
  actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.0.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (5.0.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
  rack-contrib (1.2.0) lib/rack/contrib/response_headers.rb:17:in `call'
  meta_request (0.4.0) lib/meta_request/middlewares/headers.rb:16:in `call'
  web-console (3.3.1) lib/web_console/middleware.rb:131:in `call_app'
  web-console (3.3.1) lib/web_console/middleware.rb:28:in `block in call'
  web-console (3.3.1) lib/web_console/middleware.rb:18:in `call'
  actionpack (5.0.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
  railties (5.0.0.1) lib/rails/rack/logger.rb:36:in `call_app'
  railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `block in call'
  activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `block in tagged'
  activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `tagged'
  railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `call'
  sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
  request_store (1.3.1) lib/request_store/middleware.rb:9:in `call'
  actionpack (5.0.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
  rack (2.0.1) lib/rack/method_override.rb:22:in `call'
  rack (2.0.1) lib/rack/runtime.rb:22:in `call'
  activesupport (5.0.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.0.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
  rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
  railties (5.0.0.1) lib/rails/engine.rb:522:in `call'
  puma (3.6.0) lib/puma/configuration.rb:225:in `call'
  puma (3.6.0) lib/puma/server.rb:578:in `handle_request'
  puma (3.6.0) lib/puma/server.rb:415:in `process_client'
  puma (3.6.0) lib/puma/server.rb:275:in `block in run'
  puma (3.6.0) lib/puma/thread_pool.rb:116:in `block in spawn_thread'

Received params:

  Parameters: {"utf8"=>"✓", "authenticity_token"=>"rah5u+MSVNLTcZvkwG84+A2J4zrswzHWlOihLQJxLFSmNmbauMrRZewFlEjIRO2A57XWA7jBkc/jrpBBdp1j4Q==", "dataset_structure"=>{"version"=>"", "fields_attributes"=>{"0"=>{"name"=>"name", "description"=>"description", "format"=>"string", "_destroy"=>"false"}, "1478539767383"=>{"name"=>"test", "description"=>"Test", "format"=>"string", "_destroy"=>"false"}}}, "commit"=>"Commit", "dataset_id"=>"7707778246-meduchporeabilkohlearimplant"}

Gemfile:

gem 'trailblazer-rails', '~> 0.4.0'
gem 'trailblazer-cells'
gem 'representable', '~> 3.0.0'
gem 'cells-slim'
gem 'cells-rails'
gem 'multi_json'
gem 'reform-rails', '0.1.5'

Any thoughts how to debug and fix this?

@Envek
Copy link
Author

Envek commented Nov 8, 2016

Seems like I found solution: will be fixed by #191
@apotonick can you please take a look and merge it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant