Internal error: undefined method `visibility_reason_id'

I manage a Discourse instance on https://lilypond.community. A few hours ago, I used the Web interface to upgrade Discourse to 3.3.0beta2. It failed with the same error as on 3.3.0.beta2-dev update error - #8 by david. At that moment, I didn’t have the time to investigate, so I left it as-is, but the forum still looked functional. Now it’s giving

Oops

The software powering this discussion forum encountered an unexpected problem. We apologize for the inconvenience.

Detailed information about the error was logged, and an automatic notification generated. We’ll take a look at it.

No further action is necessary. However, if the error condition persists, you can provide additional detail, including steps to reproduce the error, by posting a discussion topic in the site’s feedback category.

on any page (/, /t/topic-slug, etc).

I followed the advice on the linked topic:

cd /var/discourse
git pull
./launcher rebuild app
./launcher start app

but it didn’t help. I’m not 100% sure the problem is actually related to the upgrade, though I find it likely.

This is what I find in /var/discourse/shared/standalone/log/rails/production.log, just after trying to access the page https://lilypond.community/t/effacer-les-citations-du-conducteur/5698/8:

Started GET "/t/effacer-les-citations-du-conducteur/5698/8" for [IP redacted] at 2024-05-16 20:49:53 +0000
Processing by TopicsController#show as HTML
  Parameters: {"slug"=>"effacer-les-citations-du-conducteur", "topic_id"=>"5698", "post_number"=>"8"}
Completed 500 Internal Server Error in 39ms (ActiveRecord: 0.0ms | Allocations: 14832)
NoMethodError (undefined method `visibility_reason_id' for #<Topic id: 5698, title: "Effacer les citations du conducteur", [...]>)
app/serializers/topic_view_serializer.rb:327:in `include_visibility_reason_id?'
(eval):37:in `_fast_attributes'
app/controllers/topics_controller.rb:1360:in `block (2 levels) in perform_show_response'
app/controllers/topics_controller.rb:1354:in `perform_show_response'
app/controllers/topics_controller.rb:187:in `show'
app/controllers/application_controller.rb:423:in `block in with_resolved_locale'
app/controllers/application_controller.rb:423:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:64:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:391:in `call'
lib/middleware/csp_script_nonce_injector.rb:12:in `call'
config/initializers/008-rack-cors.rb:14:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
lib/middleware/request_tracker.rb:277:in `call'
start
done

For a user page:

Started GET "/u/jeanas/" for [IP redacted] at 2024-05-16 20:47:21 +0000
Processing by UsersController#show as HTML
  Parameters: {"username"=>"jeanas"}
Completed 500 Internal Server Error in 180ms (ActiveRecord: 0.0ms | Allocations: 80166)
NoMethodError (undefined method `custom_homepage' for #<ThemeModifierHelper:0x00007f37a9f775c8 @theme_ids=[1]>)
app/serializers/user_serializer.rb:327:in `can_pick_theme_with_custom_homepage'
(eval):100:in `_fast_attributes'
app/controllers/users_controller.rb:152:in `block (2 levels) in show'
app/controllers/users_controller.rb:149:in `show'
app/controllers/application_controller.rb:423:in `block in with_resolved_locale'
app/controllers/application_controller.rb:423:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:64:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:393:in `call'
lib/middleware/csp_script_nonce_injector.rb:12:in `call'
config/initializers/008-rack-cors.rb:14:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
lib/middleware/request_tracker.rb:277:in `call'

And for the root page:

Started GET "/" for [IP redacted] at 2024-05-16 20:54:16 +0000
NoMethodError (undefined method `custom_homepage' for #<ThemeModifierHelper:0x00007f37aba0c488 @theme_ids=[]>)
lib/homepage_helper.rb:5:in `resolve'
lib/homepage_constraint.rb:12:in `matches?'
lib/middleware/omniauth_bypass_middleware.rb:64:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:393:in `call'
lib/middleware/csp_script_nonce_injector.rb:12:in `call'
config/initializers/008-rack-cors.rb:14:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
lib/middleware/request_tracker.rb:277:in `call'

Looking at the code, it seems that visibility_reason_id and such are database fields new in this version, that were supposed to be added to the existing database by migrations scripts (e.g., db/migrate/20240423013808_add_visibility_reason_id_to_topics.rb). I suspect that the upgrade stopped halfway before running these.

Is there a way to cleanly roll back to 3.3.0beta1 and redo the migration? If I do git checkout v3.3.0.beta1 inside the Docker container (./launcher enter app), is it dangerous?

Does it still happen if you rebuild a second time? What says the rebuild log if the issue persists? :thinking:

3 Likes

Oh, that worked. Thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.