Skip to content

Fix History Page Crash (Issue #1886) #1902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions src/moin/themes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,26 +610,33 @@ def get_editor_info(meta, external=False):

userid = meta.get(USERID)
if userid:
u = user.User(userid)
name = u.name0
text = u.display_name or name
display_name = u.display_name or name
if title:
# we already have some address info
title = f"{display_name} @ {title}"
else:
title = display_name
if u.mailto_author and u.email:
email = u.email
css = "editor mail"
else:
homewiki = app.cfg.user_homewiki
if is_local_wiki(homewiki):
css = "editor homepage local"
try:
u = user.User(userid)
name = u.name0
text = u.display_name or name
display_name = u.display_name or name
if title:
# we already have some address info
title = f"{display_name} @ {title}"
else:
css = "editor homepage interwiki"
uri = url_for_item(name, wiki_name=homewiki, _external=external, namespace=NAMESPACE_USERS)

title = display_name
if u.mailto_author and u.email:
email = u.email
css = "editor mail"
else:
homewiki = app.cfg.user_homewiki
if is_local_wiki(homewiki):
css = "editor homepage local"
else:
css = "editor homepage interwiki"
uri = url_for_item(name, wiki_name=homewiki, _external=external, namespace=NAMESPACE_USERS)
except Exception:
# Fall back to default values if user profile loading fails
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please log the exception. This should not get unnoticed.
Also think about catching a more specific exception.

name = "Unknown"
text = "anonymous"
title = "Unknown User"
css = "editor unknown"

result = dict(name=name, text=text, css=css, title=title)
if uri:
result["uri"] = uri
Expand Down
36 changes: 36 additions & 0 deletions src/moin/themes/_tests/test_get_editor_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from moin.themes import get_editor_info

def test_get_editor_info_anonymous():
meta = {} # Simulate revision with no USERID or ADDRESS
result = get_editor_info(meta)
assert result["text"] == "anonymous"
assert result["title"] == ""
assert result["css"] == "editor"
assert result["name"] is None

def test_get_editor_info_with_address():
meta = {"address": "192.168.1.1"}
result = get_editor_info(meta)
assert result["text"] == "192.168.1.1"
assert result["title"] == "[192.168.1.1]"
assert result["css"] == "editor ip"

def test_get_editor_info_invalid_user(monkeypatch):
# Simulate a USERID but make user.User(userid) raise an Exception
class DummyUser:
def __init__(self, userid):
raise ValueError("Simulated broken profile")

from moin import themes
from moin import user as real_user_module

monkeypatch.setattr(themes.user, "User", DummyUser)

meta = {"userid": "fake-id"}
result = get_editor_info(meta)

assert result["text"] == "anonymous"
assert result["title"] == "Unknown User"
assert result["css"] == "editor unknown"
assert result["name"] == "Unknown"
Loading