Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions portal/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ class AppsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "portal"
verbose_name = "Studio Portal"

def ready(self):
"""
This function is used to register the signal handlers.

See
`Django documentation <https://docs.djangoproject.com/en/4.2/ref/applications/#django.apps.AppConfig.ready>`_
for more information.
"""
import portal.signals
9 changes: 9 additions & 0 deletions portal/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.dispatch import receiver

from django_structlog.signals import bind_extra_request_metadata
import structlog


@receiver(bind_extra_request_metadata)
def remove_ip_address(request, logger, **kwargs):
Copy link

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

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

The signal handler signature is missing the sender parameter. It should be defined as def remove_ip_address(sender, request, logger, **kwargs): so arguments are aligned correctly.

Suggested change
def remove_ip_address(request, logger, **kwargs):
def remove_ip_address(sender, request, logger, **kwargs):

Copilot uses AI. Check for mistakes.
structlog.contextvars.bind_contextvars(ip=None)
Copy link

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

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

Signal handlers for bind_extra_request_metadata should return a dict of metadata (e.g., return {"ip": None}) instead of only binding contextvars, otherwise the ip field may not be removed as intended.

Suggested change
structlog.contextvars.bind_contextvars(ip=None)
return {"ip": None}

Copilot uses AI. Check for mistakes.
Loading