decidim / decidim

The participatory democracy framework. A generator and multiple gems made with Ruby on Rails
https://decidim.org/
GNU Affero General Public License v3.0
1.47k stars 403 forks source link

Exception in PushNotificationPresenter (undefined method `reported_content_url') #9914

Closed andreslucena closed 1 year ago

andreslucena commented 2 years ago

Describe the bug

There's an exception in a Sidekiq job related to the Push Notifications feature

To Reproduce Steps to reproduce the behavior:

  1. Generate a push notification with a model that doesn't have a reported_content_url method (like a Component, Blogs::Post, User, are the ones that I see in Sentry)
  2. See exception in sidekiq log / Sentry

Expected behavior

To not have this exception 😄

Stacktrace

Details NoMethodError: undefined method `reported_content_url' for #"Debats", "en"=>"Debates", "es"=>"Debates"}, participatory_space_id: 38, settings: {"steps"=>{}, "global"=>{"scope_id"=>65, "announcement"=>{"ca"=>"", "en"=>"", "es"=>""}, "scopes_enabled"=>false, "announcement_ca"=>"", "announcement_cs"=>nil, "announcement_de"=>nil, "announcement_en"=>"", "announcement_es"=>"", "announcement_eu"=>nil, "announcement_fi"=>nil, "announcement_fr"=>nil, "announcement_it"=>nil, "announcement_ja"=>nil, "announcement_nl"=>nil, "announcement_pl"=>nil, "announcement_pt"=>nil, "announcement_ro"=>nil, "comments_enabled"=>true, "comments_max_length"=>2500}, "default_step"=>{"announcement"=>{"ca"=>"", "en"=>"", "es"=>""}, "announcement_ca"=>"", "announcement_cs"=>nil, "announcement_de"=>nil, "announcement_en"=>"", "announcement_es"=>"", "announcement_eu"=>nil, "announcement_fi"=>nil, "announcement_fr"=>nil, "announcement_it"=>nil, "announcement_ja"=>nil, "announcement_nl"=>nil, "announcement_pl"=>nil, "announcement_pt"=>nil, "announcement_ro"=>nil, "comments_blocked"=>false, "creation_enabled"=>true, "endorsements_blocked"=>false, "endorsements_enabled"=>true}}, weight: 2, published_at: "2022-10-20 08:50:07.167482000 +0000", permissions: nil, participatory_space_type: "Decidim::Assembly", created_at: "2022-10-19 14:19:22.897658000 +0000", updated_at: "2022-10-20 10:12:03.974303000 +0000"> from activemodel (6.1.7) lib/active_model/attribute_methods.rb:469:in `method_missing' from decidim-core (0.27.0.rc2) app/presenters/decidim/push_notification_presenter.rb:22:in `url' from decidim-core (0.27.0.rc2) app/services/decidim/send_push_notification.rb:44:in `notification_params' from decidim-core (0.27.0.rc2) app/services/decidim/send_push_notification.rb:23:in `block (2 levels) in perform' from decidim-core (0.27.0.rc2) app/services/decidim/send_push_notification.rb:22:in `map' from decidim-core (0.27.0.rc2) app/services/decidim/send_push_notification.rb:22:in `block in perform' from i18n (1.12.0) lib/i18n.rb:322:in `with_locale' from decidim-core (0.27.0.rc2) app/services/decidim/send_push_notification.rb:21:in `perform' from decidim-core (0.27.0.rc2) app/jobs/decidim/notification_generator_for_recipient_job.rb:13:in `perform' from activejob (6.1.7) lib/active_job/execution.rb:48:in `block in perform_now' from activesupport (6.1.7) lib/active_support/callbacks.rb:117:in `block in run_callbacks' from sentry-raven (3.1.2) lib/raven/integrations/rails/active_job.rb:13:in `block (2 levels) in included' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `instance_exec' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `block in run_callbacks' from i18n (1.12.0) lib/i18n.rb:322:in `with_locale' from activejob (6.1.7) lib/active_job/translation.rb:9:in `block (2 levels) in ' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `instance_exec' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `block in run_callbacks' from activesupport (6.1.7) lib/active_support/core_ext/time/zones.rb:66:in `use_zone' from activejob (6.1.7) lib/active_job/timezones.rb:9:in `block (2 levels) in ' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `instance_exec' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `block in run_callbacks' from activejob (6.1.7) lib/active_job/instrumentation.rb:21:in `block in instrument' from activesupport (6.1.7) lib/active_support/notifications.rb:203:in `block in instrument' from activesupport (6.1.7) lib/active_support/notifications/instrumenter.rb:24:in `instrument' from activesupport (6.1.7) lib/active_support/notifications.rb:203:in `instrument' from activejob (6.1.7) lib/active_job/instrumentation.rb:31:in `instrument' from activejob (6.1.7) lib/active_job/instrumentation.rb:14:in `block (2 levels) in ' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `instance_exec' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `block in run_callbacks' from activejob (6.1.7) lib/active_job/logging.rb:22:in `block in tag_logger' from activesupport (6.1.7) lib/active_support/tagged_logging.rb:99:in `block in tagged' from activesupport (6.1.7) lib/active_support/tagged_logging.rb:37:in `tagged' from activesupport (6.1.7) lib/active_support/tagged_logging.rb:99:in `tagged' from activejob (6.1.7) lib/active_job/logging.rb:22:in `tag_logger' from activejob (6.1.7) lib/active_job/logging.rb:15:in `block (2 levels) in ' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `instance_exec' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `block in run_callbacks' from activesupport (6.1.7) lib/active_support/callbacks.rb:137:in `run_callbacks' from activejob (6.1.7) lib/active_job/execution.rb:47:in `perform_now' from activejob (6.1.7) lib/active_job/execution.rb:25:in `block in execute' from activesupport (6.1.7) lib/active_support/callbacks.rb:117:in `block in run_callbacks' from activejob (6.1.7) lib/active_job/railtie.rb:47:in `block (4 levels) in ' from activesupport (6.1.7) lib/active_support/execution_wrapper.rb:91:in `wrap' from activesupport (6.1.7) lib/active_support/reloader.rb:72:in `block in wrap' from activesupport (6.1.7) lib/active_support/execution_wrapper.rb:87:in `wrap' from activesupport (6.1.7) lib/active_support/reloader.rb:71:in `wrap' from activejob (6.1.7) lib/active_job/railtie.rb:46:in `block (3 levels) in ' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `instance_exec' from activesupport (6.1.7) lib/active_support/callbacks.rb:126:in `block in run_callbacks' from activesupport (6.1.7) lib/active_support/callbacks.rb:137:in `run_callbacks' from activejob (6.1.7) lib/active_job/execution.rb:23:in `execute' from activejob (6.1.7) lib/active_job/queue_adapters/sidekiq_adapter.rb:42:in `perform' from sidekiq (6.5.6) lib/sidekiq/processor.rb:202:in `execute_job' from sidekiq (6.5.6) lib/sidekiq/processor.rb:170:in `block (2 levels) in process' from sidekiq (6.5.6) lib/sidekiq/middleware/chain.rb:177:in `block in invoke' from sentry-raven (3.1.2) lib/raven/integrations/sidekiq/cleanup_middleware.rb:7:in `call' from sidekiq (6.5.6) lib/sidekiq/middleware/chain.rb:179:in `block in invoke' from sidekiq (6.5.6) lib/sidekiq/middleware/chain.rb:182:in `invoke' from sidekiq (6.5.6) lib/sidekiq/processor.rb:169:in `block in process' from sidekiq (6.5.6) lib/sidekiq/processor.rb:136:in `block (6 levels) in dispatch' from sidekiq (6.5.6) lib/sidekiq/job_retry.rb:113:in `local' from sidekiq (6.5.6) lib/sidekiq/processor.rb:135:in `block (5 levels) in dispatch' from sidekiq (6.5.6) lib/sidekiq/rails.rb:14:in `block in call' from activesupport (6.1.7) lib/active_support/execution_wrapper.rb:91:in `wrap' from activesupport (6.1.7) lib/active_support/reloader.rb:72:in `block in wrap' from activesupport (6.1.7) lib/active_support/execution_wrapper.rb:91:in `wrap' from activesupport (6.1.7) lib/active_support/reloader.rb:71:in `wrap' from sidekiq (6.5.6) lib/sidekiq/rails.rb:13:in `call' from sidekiq (6.5.6) lib/sidekiq/processor.rb:131:in `block (4 levels) in dispatch' from sidekiq (6.5.6) lib/sidekiq/processor.rb:263:in `stats' from sidekiq (6.5.6) lib/sidekiq/processor.rb:126:in `block (3 levels) in dispatch' from sidekiq (6.5.6) lib/sidekiq/job_logger.rb:13:in `call' from sidekiq (6.5.6) lib/sidekiq/processor.rb:125:in `block (2 levels) in dispatch' from sidekiq (6.5.6) lib/sidekiq/job_retry.rb:80:in `global' from sidekiq (6.5.6) lib/sidekiq/processor.rb:124:in `block in dispatch' from sidekiq (6.5.6) lib/sidekiq/job_logger.rb:39:in `prepare' from sidekiq (6.5.6) lib/sidekiq/processor.rb:123:in `dispatch' from sidekiq (6.5.6) lib/sidekiq/processor.rb:168:in `process' from sidekiq (6.5.6) lib/sidekiq/processor.rb:78:in `process_one' from sidekiq (6.5.6) lib/sidekiq/processor.rb:68:in `run' from sidekiq (6.5.6) lib/sidekiq/component.rb:8:in `watchdog' from sidekiq (6.5.6) lib/sidekiq/component.rb:17:in `block in safe_thread'

Extra data (please complete the following information):

andreslucena commented 2 years ago

The culprit is here:

https://github.com/decidim/decidim/blob/e79de5044f9d5bf9492685189dc21606751829e5/decidim-core/app/presenters/decidim/push_notification_presenter.rb#L22

So it probably need to implement ResourceLocatorPresenter or something similar.

@ferblape can you check this out please?

andreslucena commented 2 years ago

Ah and it'll need a spec for sure