Skip to content
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

fix: Logging error for logged in user #2613

Merged
merged 1 commit into from
Mar 19, 2025
Merged
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
5 changes: 5 additions & 0 deletions apps/common/log/log.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
@date:2025/3/14 16:09
@desc:
"""
from gettext import gettext

from setting.models.log_management import Log

@@ -31,6 +32,10 @@ def _get_user(request):
@return:
"""
user = request.user
if user is None:
return {
"user_name": gettext('unknown')
}
return {
"id": str(user.id),
"email": user.email,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code does not contain any syntax errors or obvious issues. However, here's an additional optimization suggestion:

def _get_user(request):
    user = request.user
    if user:
        return {
            "id": str(user.id),
            "email": user.email,
        }

    # Return a common placeholder for unknown users
    return {
        "user_name": gettext("unknown"),
    }

This slightly optimizes the function by reducing redundancy and making it more readable, although performance has minimal impact on this simple function.