Apotomo Phantom Child already added

48 views
Skip to first unread message

rmen...@itu.edu

unread,
Jan 1, 2014, 8:50:36 PM1/1/14
to cells-an...@googlegroups.com
I am having trouble debugging an error, the error is

Child already added

It occurs when I am rendering a page with multiple widgets. It's difficult to debug because it's intermittent, and I'm hitting a wall in figuring out how I've duplicated it. Has anyone else solved this?

I am trying to render multiples of the same widget, in my controller, I differentiate them with an id,

has_widgets do |root|
root << widget("namespaced/widget_name", :widget1, :data => @data, :more_data => "some more data")
root << widget("namespaced/widget_name", :widget2, :data => @data, :more_data => "different data")
root << widget("namespaced/widget_name", :widget3, :data => @data, :more_data => "different data")


Then in the view render them like:

= render_widget :widget2
= render_widget :widget1
= render_widget :widget3

The "more_data" is correct in each widget, and things work well, then they don't and I get the error above. If anyone has any hints on what I am doing wrong, I would really appreciate hearing them.

Happy New Year!

Rebecca

P.S. My stack trace looks like this

apotomo (1.2.5) lib/apotomo/widget/tree_node.rb:24:in `add_widget' apotomo (1.2.5) lib/apotomo/widget/tree_node.rb:14:in `setup_tree_node' apotomo (1.2.5) lib/apotomo/widget.rb:87:in `initialize' apotomo (1.2.5) lib/apotomo/widget_shortcuts.rb:44:in `new' apotomo (1.2.5) lib/apotomo/widget_shortcuts.rb:44:in `build' apotomo (1.2.5) lib/apotomo/widget_shortcuts.rb:58:in `<<' app/controllers/faculty/courseterms_controller.rb:32:in `block in policies' apotomo (1.2.5) lib/apotomo/request_processor.rb:23:in `instance_exec' apotomo (1.2.5) lib/apotomo/request_processor.rb:23:in `block in attach_stateless_blocks_for' apotomo (1.2.5) lib/apotomo/request_processor.rb:23:in `each' apotomo (1.2.5) lib/apotomo/request_processor.rb:23:in `attach_stateless_blocks_for' apotomo (1.2.5) lib/apotomo/request_processor.rb:17:in `initialize' apotomo (1.2.5) lib/apotomo/rails/controller_methods.rb:53:in `new' apotomo (1.2.5) lib/apotomo/rails/controller_methods.rb:53:in `apotomo_request_processor' apotomo (1.2.5) lib/apotomo/rails/controller_methods.rb:61:in `render_widget' apotomo (1.2.5) lib/apotomo/rails/controller_methods.rb:15:in `render_widget' app/views/faculty/courseterms/policies.html.haml:29:in `_app_views_faculty_courseterms_policies_html_haml__1520038687485135479_70096198551320' actionpack (3.2.13) lib/action_view/template.rb:145:in `block in render' activesupport (3.2.13) lib/active_support/notifications.rb:125:in `instrument' actionpack (3.2.13) lib/action_view/template.rb:143:in `render' actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template' actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument' activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument' activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument' activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument' actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument' actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template' actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout' actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:45:in `render_template' actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:18:in `render' newrelic_rpm (3.7.0.177) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:160:in `block in render_with_newrelic' newrelic_rpm (3.7.0.177) lib/new_relic/agent/method_tracer.rb:276:in `trace_execution_scoped' newrelic_rpm (3.7.0.177) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:159:in `render_with_newrelic' actionpack (3.2.13) lib/action_view/renderer/renderer.rb:36:in `render_template' actionpack (3.2.13) lib/action_view/renderer/renderer.rb:17:in `render' actionpack (3.2.13) lib/abstract_controller/rendering.rb:110:in `_render_template' actionpack (3.2.13) lib/action_controller/metal/streaming.rb:225:in `_render_template' actionpack (3.2.13) lib/abstract_controller/rendering.rb:103:in `render_to_body' actionpack (3.2.13) lib/action_controller/metal/renderers.rb:28:in `render_to_body' actionpack (3.2.13) lib/action_controller/metal/compatibility.rb:50:in `render_to_body' actionpack (3.2.13) lib/abstract_controller/rendering.rb:88:in `render' actionpack (3.2.13) lib/action_controller/metal/rendering.rb:16:in `render' actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render' activesupport (3.2.13) lib/active_support/core_ext/benchmark.rb:5:in `block in ms' /Users/rebeccamengell/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/benchmark.rb:296:in `realtime' activesupport (3.2.13) lib/active_support/core_ext/benchmark.rb:5:in `ms' actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:40:in `block in render' actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime' activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime' actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:39:in `render' actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:10:in `default_render' actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:5:in `send_action' actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action' actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action' actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action' activesupport (3.2.13) lib/active_support/callbacks.rb:524:in `_run__4497813272331767806__process_action__1742804043326466110__callbacks' activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback' activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action' actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action' actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument' activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument' activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument' actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action' actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action' activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action' newrelic_rpm (3.7.0.177) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:38:in `block in process_action' newrelic_rpm (3.7.0.177) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:339:in `perform_action_with_newrelic_trace' newrelic_rpm (3.7.0.177) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:37:in `process_action' actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process' actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process' actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch' actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action' actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `call' actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch' actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:36:in `call' journey (1.0.4) lib/journey/router.rb:68:in `block in call' journey (1.0.4) lib/journey/router.rb:56:in `each' journey (1.0.4) lib/journey/router.rb:56:in `call' actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in `call' newrelic_rpm (3.7.0.177) lib/new_relic/rack/error_collector.rb:50:in `call' newrelic_rpm (3.7.0.177) lib/new_relic/rack/agent_hooks.rb:28:in `call' newrelic_rpm (3.7.0.177) lib/new_relic/rack/browser_monitoring.rb:23:in `call' newrelic_rpm (3.7.0.177) lib/new_relic/rack/developer_mode.rb:42:in `call' request_store (1.0.5) lib/request_store/middleware.rb:9:in `call' warden (1.2.3) lib/warden/manager.rb:35:in `block in call' warden (1.2.3) lib/warden/manager.rb:34:in `catch' warden (1.2.3) lib/warden/manager.rb:34:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' rack (1.4.5) lib/rack/etag.rb:23:in `call' rack (1.4.5) lib/rack/conditionalget.rb:25:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call' rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context' rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call' activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call' activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__207778201101263293__call__2466851919228565168__callbacks' activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback' activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks' activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app' railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call' activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged' railties (3.2.13) lib/rails/rack/logger.rb:16:in `call' quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets' actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call' rack (1.4.5) lib/rack/methodoverride.rb:21:in `call' rack (1.4.5) lib/rack/runtime.rb:17:in `call' activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call' rack (1.4.5) lib/rack/lock.rb:15:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call' railties (3.2.13) lib/rails/engine.rb:479:in `call' railties (3.2.13) lib/rails/application.rb:223:in `call' rack (1.4.5) lib/rack/content_length.rb:14:in `call' railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call' thin (1.6.1) lib/thin/connection.rb:82:in `block in pre_process' thin (1.6.1) lib/thin/connection.rb:80:in `catch' thin (1.6.1) lib/thin/connection.rb:80:in `pre_process' thin (1.6.1) lib/thin/connection.rb:55:in `process' thin (1.6.1) lib/thin/connection.rb:41:in `receive_data' eventmachine (1.0.3) lib/eventmachine.rb:187:in `run_machine' eventmachine (1.0.3) lib/eventmachine.rb:187:in `run' thin (1.6.1) lib/thin/backends/base.rb:73:in `start' thin (1.6.1) lib/thin/server.rb:162:in `start' rack (1.4.5) lib/rack/handler/thin.rb:13:in `run' rack (1.4.5) lib/rack/server.rb:268:in `start' railties (3.2.13) lib/rails/commands/server.rb:70:in `start' railties (3.2.13) lib/rails/commands.rb:55:in `block in <top (required)>' railties (3.2.13) lib/rails/commands.rb:50:in `tap' railties (3.2.13) lib/rails/commands.rb:50:in `<top (required)>' script/rails:6:in `require' script/rails:6:in `<main>'

Nick Sutterer

unread,
Jan 2, 2014, 1:27:41 AM1/2/14
to cells-an...@googlegroups.com
Hey Rebecca,

that looks odd. First, remove the #render_widget calls. Then, can you try adding the widgets step-wise to root (eg only one, then two of them, ...)?

The name of the "child" that has already been added would actually be helpful in the exception message, I'll fix that.

Nick


--
Sie erhalten diese Nachricht, weil Sie Mitglied der Google Groups-Gruppe "Cells and Apotomo" sind.
Um Ihr Abonnement für diese Gruppe zu beenden und keine E-Mails mehr von dieser Gruppe zu erhalten, senden Sie eine E-Mail an cells-and-apot...@googlegroups.com.
Weitere Optionen: https://groups.google.com/groups/opt_out

Rebecca Mengell

unread,
Jan 2, 2014, 4:53:51 PM1/2/14
to cells-an...@googlegroups.com
I think this has something to do with how I am instantiating the widgets maybe combined with caching. 

I wanted greater encapsulation, so I put my has_widget block in a method. That is:

class FoodController < ApplicationController

   def healthy
FoodController.has_widgets do |root|
 root << widget(“namespace/process”, :healthy1 :food => “apple”)
 root << widget(“namespace/process”, :healthy2 :food => “fish”)
end
   end


  def junk
    FoodController.has_widgets do |root|
 root << widget(“namespace/process", :junk1, :food => “fries”)
 root << widget(“namespace/process", :junk2, :food => “big mac”)
end
  end
end

I think it’s an instantiation issue because when I get the error, if I save the controller again, it goes away.  

After thinking about it, I reorganized the architecture to remove the duplicates. But I still get the error. Does this sound like instantiation might be the problem?

Oh, and I was able to get some tests working. It seems it was a syntax issue coupled with my not ibuilding my widgets trees correctly. If you are interested, I would be happy to help update the documentation once I get things finished. 

Rebecca


Sie erhalten diese Nachricht, weil Sie in Google Groups ein Thema der Gruppe "Cells and Apotomo" abonniert haben.
Um Ihr Abonnement für dieses Thema zu beenden, rufen Sie die URL https://groups.google.com/d/topic/cells-and-apotomo/1A-md-XKlQQ/unsubscribe auf.
Um Ihr Abonnement für diese Gruppe und alle ihre Themen zu beenden, senden Sie eine E-Mail an cells-and-apot...@googlegroups.com.
Weitere Optionen: https://groups.google.com/groups/opt_out

Nick Sutterer

unread,
Jan 2, 2014, 7:02:35 PM1/2/14
to cells-an...@googlegroups.com
Now I wonder where you call those #healthy and #junk methods? And: are you using events with your widgets (eg submitting a form triggers an event)? If yes, your approach is not gonna work. ::has_widgets must be called on the class level to make the widget tree "persistent" between requests.

Updating the docs sounds great.

Rebecca Mengell

unread,
Jan 3, 2014, 1:31:06 PM1/3/14
to cells-an...@googlegroups.com
Sorry, that’s me trying to simplify my explination and making it more difficult to understand. 

This was a contrived example, healthy and junk should have been named show and index. The render is called by their corresponding RESTful view.

Thanks for the feedback. I will take a better look at Apotomo this weekend to figure out the best way to meet my goals.

Nick Sutterer

unread,
Jan 3, 2014, 5:25:40 PM1/3/14
to cells-an...@googlegroups.com
Ok, I think I understand what you were desperatly trying to picture :)

has_widgets is not designed to be called in actions - that's why it is a class method. I guess your problem is that the controller class gets cached. Your subsequent has_widgets invocations redefine already existing widgets.

Here's how it works so far.

* has_widgets defines the widget tree - this is done on class level so the widget tree is available in any action.
* When rendering, #render_widget can find the widget in the widget tree.
* When processing an event (do you already do that), the special action #render_event_response finds the widget using the widget tree


Reply all
Reply to author
Forward
0 new messages