Start page broken for admins & moderators

AI-generated summary

In a Discourse forum running v2.0.0.beta2, admins and moderators encountered a 500 Internal Server Error when accessing the start page, while regular and logged-out users experienced no issues. The error originated in category.rb at line 439, where parent_category was nil despite parent_category_id being set — suggesting a topic or category referenced a non-existent parent. jonasth theorized this was due to a broken topic visible only to privileged users. After investigation, jonasth resolved the issue: a category had been created with an invalid (non-existing) parent_category_id. Fixing or removing that misconfigured category restored access to the start page for admins and moderators. The error did not affect other views (e.g., category or thread pages) or the admin panel. This appears to be a data integrity issue rather than a code bug, likely caused by manual or script-based category creation without validating parent references. No workaround was needed beyond correcting the category record in the database.

Hi,

We have a discourse forum where admins and moderators currently can’t visit the start page, because it renders a 500 Internal Server Error page. It works fine for normal users and logged-out users.

Separate thread and category views work fine for all users (including admins/moderators), and the admin page works fine.

Discourse version: v2.0.0.beta2

The error in the logs:

/var/www/discourse/app/models/category.rb:439:in `url'
/var/www/discourse/app/helpers/topics_helper.rb:16:in `categories_breadcrumb'
/var/www/discourse/app/views/topics/show.html.erb:5:in `_app_views_topics_show_html_erb___1372095578456862489_70244849918320'
/var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionview-5.1.4/lib/action_view/template.rb:157:in `block in render'

The line where it blows up:
url << "/#{parent_category.slug}" if parent_category_id

Looking at the backtrace and the code (I am not a ruby dev) it seems it’s building a list of topics for the start page. The parent_category variable is null but the parent_category_id is set, so I think there’s a topic with a reference to a non-existing category?

In that case there’s a broken topic with a non-existing category that only admins and moderators can see.

Has anyone seen this error before?
Or maybe a suggestion how to find this broken topic in the database?

Cheers

Resolved. A category was created with a non-existing parent category ID.