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

Header extraction failing with helper class #85

Closed
bvogel opened this issue Dec 9, 2013 · 2 comments · Fixed by #86
Closed

Header extraction failing with helper class #85

bvogel opened this issue Dec 9, 2013 · 2 comments · Fixed by #86

Comments

@bvogel
Copy link

bvogel commented Dec 9, 2013

We use a helper class to extract our csv formatings from our model class. This will break from versions 3.1 onwards, 3.0.6 was the last working version.

Model:

class Article < ActiveRecord::Base
  belongs_to :brand
  belongs_to :category

  comma do
    article_no 'Article-No'
    csv_formatter brand_name: 'Marke', model_name: 'Variante'
  end
protected
  def csv_formatter
    @csv_formatter ||= ArticleCsvFormatter.new(self, self.category, self.brand)
  end
end

Helper:

class ArticleCsvFormatter
  def initialize(article, category, brand)
    @article = article
    @category = category
    @brand = brand
  end

  def brand_name
    @brand.name
  end

  def model_name
    @category.model_name if @category
  end
end

Error message:
NoMethodError: undefined method `klass' for nil:NilClass

Stacktrace:

/gems/comma-3.2.0/lib/comma/header_extractor.rb:45 in "get_association_class"
/gems/comma-3.2.0/lib/comma/header_extractor.rb:25 in "block (2 levels) in method_missing"
/gems/comma-3.2.0/lib/comma/header_extractor.rb:24 in "each"
/gems/comma-3.2.0/lib/comma/header_extractor.rb:24 in "block in method_missing"
/gems/comma-3.2.0/lib/comma/header_extractor.rb:21 in "each"
/gems/comma-3.2.0/lib/comma/header_extractor.rb:21 in "method_missing"
[/app/models/article.rb:81 in "block in &lt;class:Article&gt;"](https://github.com/reverseretail/buddy/tree/master/app/models/article.rb#L81)
/gems/comma-3.2.0/lib/comma/extractor.rb:15 in "instance_eval"
/gems/comma-3.2.0/lib/comma/extractor.rb:15 in "results"
/gems/comma-3.2.0/lib/comma/object.rb:24 in "extract_with"
/gems/comma-3.2.0/lib/comma/object.rb:17 in "to_comma_headers"
/gems/comma-3.2.0/lib/comma/generator.rb:30 in "append_csv"
/gems/comma-3.2.0/lib/comma/generator.rb:21 in "block in run"
[/usr/local/lib/ruby/1.9.1/csv.rb:1243 in "generate"](https://github.com/reverseretail/buddy/tree/master/usr/local/lib/ruby/1.9.1/csv.rb#L1243)
/gems/comma-3.2.0/lib/comma/generator.rb:21 in "run"
/gems/comma-3.2.0/lib/comma/relation.rb:3 in "to_comma"
[/lib/services/excel_export.rb:53 in "export_csv"](https://github.com/reverseretail/buddy/tree/master/lib/services/excel_export.rb#L53)
[/app/controllers/articles_controller.rb:42 in "block (2 levels) in index"](https://github.com/reverseretail/buddy/tree/master/app/controllers/articles_controller.rb#L42)
/gems/actionpack-3.2.15/lib/action_controller/metal/mime_responds.rb:196 in "call"
/gems/actionpack-3.2.15/lib/action_controller/metal/mime_responds.rb:196 in "respond_to"
[/app/controllers/articles_controller.rb:39 in "index"](https://github.com/reverseretail/buddy/tree/master/app/controllers/articles_controller.rb#L39)
/gems/actionpack-3.2.15/lib/action_controller/metal/implicit_render.rb:4 in "send_action"
/gems/actionpack-3.2.15/lib/abstract_controller/base.rb:167 in "process_action"
/gems/actionpack-3.2.15/lib/action_controller/metal/rendering.rb:10 in "process_action"
/gems/actionpack-3.2.15/lib/abstract_controller/callbacks.rb:18 in "block in process_action"
/gems/activesupport-3.2.15/lib/active_support/callbacks.rb:502 in "_run__258860530__process_action__818133685__callbacks"
/gems/activesupport-3.2.15/lib/active_support/callbacks.rb:405 in "__run_callback"
/gems/activesupport-3.2.15/lib/active_support/callbacks.rb:385 in "_run_process_action_callbacks"
/gems/activesupport-3.2.15/lib/active_support/callbacks.rb:81 in "run_callbacks"
/gems/actionpack-3.2.15/lib/abstract_controller/callbacks.rb:17 in "process_action"
/gems/actionpack-3.2.15/lib/action_controller/metal/rescue.rb:29 in "process_action"
/gems/actionpack-3.2.15/lib/action_controller/metal/instrumentation.rb:30 in "block in process_action"
/gems/activesupport-3.2.15/lib/active_support/notifications.rb:123 in "block in instrument"
/gems/activesupport-3.2.15/lib/active_support/notifications/instrumenter.rb:20 in "instrument"
/gems/activesupport-3.2.15/lib/active_support/notifications.rb:123 in "instrument"
/gems/actionpack-3.2.15/lib/action_controller/metal/instrumentation.rb:29 in "process_action"
/gems/actionpack-3.2.15/lib/action_controller/metal/params_wrapper.rb:207 in "process_action"
/gems/activerecord-3.2.15/lib/active_record/railties/controller_runtime.rb:18 in "process_action"
/gems/newrelic_rpm-3.6.9.171/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:38 in "block in process_action"
/gems/newrelic_rpm-3.6.9.171/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:339 in "perform_action_with_newrelic_trace"
/gems/newrelic_rpm-3.6.9.171/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:37 in "process_action"
/gems/actionpack-3.2.15/lib/abstract_controller/base.rb:121 in "process"
/gems/actionpack-3.2.15/lib/abstract_controller/rendering.rb:45 in "process"
/gems/rack-mini-profiler-0.1.31/Ruby/lib/mini_profiler/profiling_methods.rb:79 in "block in profile_method"
/gems/actionpack-3.2.15/lib/action_controller/metal.rb:203 in "dispatch"
/gems/actionpack-3.2.15/lib/action_controller/metal/rack_delegation.rb:14 in "dispatch"
/gems/actionpack-3.2.15/lib/action_controller/metal.rb:246 in "block in action"
/gems/actionpack-3.2.15/lib/action_dispatch/routing/route_set.rb:73 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/routing/route_set.rb:73 in "dispatch"
/gems/actionpack-3.2.15/lib/action_dispatch/routing/route_set.rb:36 in "call"
/gems/journey-1.0.4/lib/journey/router.rb:68 in "block in call"
/gems/journey-1.0.4/lib/journey/router.rb:56 in "each"
/gems/journey-1.0.4/lib/journey/router.rb:56 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/routing/route_set.rb:608 in "call"
/gems/newrelic_rpm-3.6.9.171/lib/new_relic/rack/error_collector.rb:50 in "call"
/gems/newrelic_rpm-3.6.9.171/lib/new_relic/rack/agent_hooks.rb:28 in "call"
/gems/newrelic_rpm-3.6.9.171/lib/new_relic/rack/browser_monitoring.rb:23 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/middleware/best_standards_support.rb:17 in "call"
/gems/rack-1.4.5/lib/rack/etag.rb:23 in "call"
/gems/rack-1.4.5/lib/rack/conditionalget.rb:25 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/middleware/head.rb:14 in "call"
/gems/remotipart-1.2.1/lib/remotipart/middleware.rb:27 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/middleware/params_parser.rb:21 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/middleware/flash.rb:242 in "call"
/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:210 in "context"
/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/middleware/cookies.rb:341 in "call"
/gems/activerecord-3.2.15/lib/active_record/query_cache.rb:64 in "call"
/gems/activerecord-3.2.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:479 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/middleware/callbacks.rb:28 in "block in call"
/gems/activesupport-3.2.15/lib/active_support/callbacks.rb:405 in "_run__348730247__call__821351200__callbacks"
/gems/activesupport-3.2.15/lib/active_support/callbacks.rb:405 in "__run_callback"
/gems/activesupport-3.2.15/lib/active_support/callbacks.rb:385 in "_run_call_callbacks"
/gems/activesupport-3.2.15/lib/active_support/callbacks.rb:81 in "run_callbacks"
/gems/actionpack-3.2.15/lib/action_dispatch/middleware/callbacks.rb:27 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/middleware/remote_ip.rb:31 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/middleware/debug_exceptions.rb:16 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/middleware/show_exceptions.rb:56 in "call"
/gems/railties-3.2.15/lib/rails/rack/logger.rb:32 in "call_app"
/gems/railties-3.2.15/lib/rails/rack/logger.rb:16 in "block in call"
/gems/activesupport-3.2.15/lib/active_support/tagged_logging.rb:22 in "tagged"
/gems/railties-3.2.15/lib/rails/rack/logger.rb:16 in "call"
/gems/actionpack-3.2.15/lib/action_dispatch/middleware/request_id.rb:22 in "call"
/gems/rack-1.4.5/lib/rack/methodoverride.rb:21 in "call"
/gems/rack-1.4.5/lib/rack/runtime.rb:17 in "call"
/gems/activesupport-3.2.15/lib/active_support/cache/strategy/local_cache.rb:72 in "call"
/gems/rack-1.4.5/lib/rack/lock.rb:15 in "call"
/gems/rack-ssl-1.3.3/lib/rack/ssl.rb:27 in "call"
/gems/rack-cache-1.2/lib/rack/cache/context.rb:136 in "forward"
/gems/rack-cache-1.2/lib/rack/cache/context.rb:245 in "fetch"
/gems/rack-cache-1.2/lib/rack/cache/context.rb:185 in "lookup"
/gems/rack-cache-1.2/lib/rack/cache/context.rb:66 in "call!"
/gems/rack-cache-1.2/lib/rack/cache/context.rb:51 in "call"
/gems/rack-mini-profiler-0.1.31/Ruby/lib/mini_profiler/profiler.rb:189 in "call"
/gems/railties-3.2.15/lib/rails/engine.rb:484 in "call"
/gems/railties-3.2.15/lib/rails/application.rb:231 in "call"
/gems/railties-3.2.15/lib/rails/railtie/configurable.rb:30 in "method_missing"
[/usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/lib/phusion_passenger/rack/thread_handler_extension.rb:77 in "process_request"](https://github.com/reverseretail/buddy/tree/master/usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/lib/phusion_passenger/rack/thread_handler_extension.rb#L77)
[/usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:140 in "accept_and_process_next_request"](https://github.com/reverseretail/buddy/tree/master/usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb#L140)
[/usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb:108 in "main_loop"](https://github.com/reverseretail/buddy/tree/master/usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/lib/phusion_passenger/request_handler/thread_handler.rb#L108)
[/usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/lib/phusion_passenger/request_handler.rb:441 in "block (3 levels) in start_threads"](https://github.com/reverseretail/buddy/tree/master/usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/lib/phusion_passenger/request_handler.rb#L441)

Model and Helper class have been reduced to avoid complexity, line numbers in the stack trace may not coincide, but the error occurs when csv_formatter will be called for the first time.

eitoball added a commit to eitoball/comma that referenced this issue Dec 9, 2013
eitoball added a commit to eitoball/comma that referenced this issue Dec 9, 2013
eitoball added a commit to eitoball/comma that referenced this issue Dec 9, 2013
eitoball added a commit to eitoball/comma that referenced this issue Dec 9, 2013
eitoball added a commit to eitoball/comma that referenced this issue Dec 9, 2013
eitoball added a commit to eitoball/comma that referenced this issue Dec 9, 2013
eitoball added a commit to eitoball/comma that referenced this issue Dec 9, 2013
@bvogel
Copy link
Author

bvogel commented May 14, 2014

Hi Guys - this fix hasn't fixed the issue for me even with 3.2.0 I get the same error message. Only with 4a14a78 has this issue been fixed (hat tip to @epdejager) - but this commit ins't included in any release yet. Currently I forked and uped the version but I'd prefer If the current codebase would get a release.

@eitoball
Copy link
Contributor

@bvogel Thanks for your heads-up.

We are preparing for version 3.2.1 and will release it soon.

@crafterm @tommeier Could you release 3.2.1? If you can add me (eitoball@gmail.com) to comma gem authors on ruby gems.org, I can release 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

Successfully merging a pull request may close this issue.

2 participants