Wagtail Comments admin menu returns 500 at /cms/snippets/comments/comment/ #37

Closed
opened 2026-03-03 13:14:28 +00:00 by mark · 0 comments
Owner

Summary

Opening Comments from the Wagtail admin menu routes to /cms/snippets/comments/comment/ and returns HTTP 500.

Reproduction

  1. Log in to Wagtail admin as a user with snippet access.
  2. Click Comments in the main admin menu.
  3. Observe a 500 error on /cms/snippets/comments/comment/.

Confirmed locally with:

docker compose run --rm -e ALLOWED_HOSTS='testserver,localhost,127.0.0.1,web' web python manage.py shell -c "from django.contrib.auth import get_user_model; from django.test import Client; U=get_user_model(); u, _ = U.objects.get_or_create(username='tmpadmin', defaults={'email':'tmpadmin@example.com','is_staff':True,'is_superuser':True}); u.is_staff=True; u.is_superuser=True; u.save(); c=Client(); c.force_login(u); c.get('/cms/snippets/comments/comment/')"

Root cause

CommentViewSet.list_display in apps/comments/wagtail_hooks.py includes "pending_in_article" as a string:

list_display = ["author_name", "article", BooleanColumn("is_approved"), "pending_in_article", "created_at"]

Wagtail resolves string columns via Django admin label_for_field against the model (Comment).
Comment has no model field/attribute named pending_in_article, so Wagtail raises:

  • FieldDoesNotExist: Comment has no field named 'pending_in_article'
  • AttributeError: Unable to lookup 'pending_in_article' on Comment

The pending_in_article method defined on the viewset is not used by this lookup path.

Proposed solution

Use an explicit table column object for the annotated value instead of a string list_display entry.

Suggested code change

  • In apps/comments/wagtail_hooks.py:
    • Import Column from wagtail.admin.ui.tables.
    • Replace "pending_in_article" in list_display with Column("pending_in_article", label="Pending (article)").
    • Remove the unused pending_in_article viewset method and short_description assignment.

Regression test

Add an admin view test that logs in a superuser and requests /cms/snippets/comments/comment/, asserting 200 OK.
This catches future list_display misconfigurations that only fail during Wagtail column construction.

Impact

  • Current behavior blocks moderation UI for comments.
  • Fix scope is small and isolated to comments snippet admin configuration.
## Summary Opening **Comments** from the Wagtail admin menu routes to `/cms/snippets/comments/comment/` and returns **HTTP 500**. ## Reproduction 1. Log in to Wagtail admin as a user with snippet access. 2. Click **Comments** in the main admin menu. 3. Observe a 500 error on `/cms/snippets/comments/comment/`. Confirmed locally with: ```bash docker compose run --rm -e ALLOWED_HOSTS='testserver,localhost,127.0.0.1,web' web python manage.py shell -c "from django.contrib.auth import get_user_model; from django.test import Client; U=get_user_model(); u, _ = U.objects.get_or_create(username='tmpadmin', defaults={'email':'tmpadmin@example.com','is_staff':True,'is_superuser':True}); u.is_staff=True; u.is_superuser=True; u.save(); c=Client(); c.force_login(u); c.get('/cms/snippets/comments/comment/')" ``` ## Root cause `CommentViewSet.list_display` in `apps/comments/wagtail_hooks.py` includes `"pending_in_article"` as a **string**: ```python list_display = ["author_name", "article", BooleanColumn("is_approved"), "pending_in_article", "created_at"] ``` Wagtail resolves string columns via Django admin `label_for_field` against the **model** (`Comment`). `Comment` has no model field/attribute named `pending_in_article`, so Wagtail raises: - `FieldDoesNotExist: Comment has no field named 'pending_in_article'` - `AttributeError: Unable to lookup 'pending_in_article' on Comment` The `pending_in_article` method defined on the **viewset** is not used by this lookup path. ## Proposed solution Use an explicit table column object for the annotated value instead of a string list_display entry. ### Suggested code change - In `apps/comments/wagtail_hooks.py`: - Import `Column` from `wagtail.admin.ui.tables`. - Replace `"pending_in_article"` in `list_display` with `Column("pending_in_article", label="Pending (article)")`. - Remove the unused `pending_in_article` viewset method and `short_description` assignment. ### Regression test Add an admin view test that logs in a superuser and requests `/cms/snippets/comments/comment/`, asserting `200 OK`. This catches future list_display misconfigurations that only fail during Wagtail column construction. ## Impact - Current behavior blocks moderation UI for comments. - Fix scope is small and isolated to comments snippet admin configuration.
mark referenced this issue from a commit 2026-03-03 13:21:09 +00:00
mark closed this issue 2026-03-03 13:31:40 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: nohype/main-site#37