← Back to Pull requests

Added admin logentry #662

Closed
unknown closed this pull request without merging on Mar 17, 2026 09:45 UTC
View on GitHub
unknown unknown commented on Mar 15, 2026 23:08 UTC
Author

Summary

  • Recorded config changes in Django's LogEntry (django_admin_log) table when values are modified via the constance admin interface.

  • Since just adding the Logentries does not add much benefit yet, I added a "History" page at /admin/constance/config/history/ with a standard Django history table (date/time, user, action).

  • Added a "History" button to the constance changelist page.

  • Made "Recent actions" entries on the admin index page link back to the constance changelist.
  • Context / Why


  • Closes #635

  • Constance config changes were completely unaudited — there was no record of who changed what or when. This made debugging configuration-related issues difficult, especially in multi-admin environments.

  • Django's built-in LogEntry infrastructure is the standard mechanism for this and is already used by every other ModelAdmin.
  • What changed

    constance/forms.py


  • ConstanceForm.save() now returns a list of config field names that were actually modified (previously returned None implicitly). Backwards-compatible — callers that ignored the return value are unaffected.
  • constance/admin.py


  • _log_config_change(request, changed_fields): Creates a LogEntry using LogEntry.objects.create() directly rather than the deprecated log_action() (deprecated in Django 5.0, removed in 6.0) or log_actions() (requires a queryset, incompatible with the fake Config model). Uses Django's standard JSON change_message format so LogEntry.get_change_message() renders correctly.

  • changelist_view: After a successful save, creates a LogEntry only if fields actually changed.

  • history_view: New view that queries LogEntry records filtered by the Config content type. Includes pagination (100 per page) and permission checks. Modelled after Django's built-in ModelAdmin.history_view.

  • get_urls(): Added history/ route and a <object_id>/change/ redirect route (so "Recent actions" sidebar links resolve instead of returning None).
  • Templates


  • change_list.html: Added "History" button using standard Django object-tools markup.

  • config_history.html (new): History page template based on Django's admin/object_history.html with constance-appropriate breadcrumbs (Home > Constance > Config > History).
  • tests/test_admin.py


  • 7 new tests: test_log_entry_created_on_change, test_no_log_entry_when_no_changes, test_history_view, test_history_view_empty, test_history_view_permission_denied, test_changelist_has_history_link, test_change_url_redirects_to_changelist.

  • Updated existing test_submit mock to match new save() return type ([] instead of None).

  • Added ContentType.objects.clear_cache() in setUp to prevent stale FK references across test transactions.
  • How to test


  • DJANGO_SETTINGS_MODULE=tests.settings python3 -m pytest tests/test_admin.py -v — all 21 tests pass.

  • DJANGO_SETTINGS_MODULE=tests.settings python3 -m pytest tests/ -v — full suite: 156 passed, 1 skipped (pre-existing).

  • Manual: change a config value in admin, check "Recent actions" sidebar shows the entry, click "History" button on constance page to see the full audit log.
  • Notes


  • Alternative Django Admin interfaces that overwrite out template like Django Unfold will not work out of the box. We'll have to raise issues there as soon as this is released.

  • We use LogEntry.objects.create() directly, which avoids both the deprecated log_action() (Django 5.0+) and log_actions() (requires a queryset, not available in Django 4.2). This is future-proof across all supported Django versions (4.2–5.2).
  • Diff: 459 lines (+344 / -115) across 5 files Reviewer: Mogost Review duration: 2076m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.46) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 459 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.367
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #662"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.5% (MEDIUM) · Higher = larger blast radius
    45.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.7% · Safe to merge
    19.7%