Skip to content

Conversation

@jgillard
Copy link
Contributor

@jgillard jgillard commented Dec 7, 2025

I hope I'm not stepping on toes with this, but I was following the issue thread and thought I'd give it a go. This is Claude Opus 4.5 assisted. I have verified that this fix works with my Django project. The Claude summary is below.

Summary

  • Fixed AttributeError: 'Settings' object has no attribute 'AUDITLOG_LOGENTRY_MODEL' that occurs when upgrading to 3.4.0+ without explicitly setting AUDITLOG_LOGENTRY_MODEL
  • Added regression test to prevent this issue from recurring

Problem

When Django's admin autodiscover imports auditlog/admin.pymixins.py, the get_logentry_model() function is called at module load time before conf.py has a chance to apply the default value.

Solution

Use getattr() with the default value directly in get_logentry_model():

model_string = getattr(settings, "AUDITLOG_LOGENTRY_MODEL", "auditlog.LogEntry")

This ensures the default is available regardless of import order, while still respecting user-defined custom values.

Changes

  • auditlog/__init__.py: Add getattr() fallback in get_logentry_model()
  • auditlog_tests/tests.py: Add regression test test_logentry_model_default_when_setting_missing

Fixes #788

)

Use getattr() with default value in get_logentry_model() to handle
cases where conf.py hasn't been imported yet due to import order.

Adds regression test to verify the fix.
@codecov
Copy link

codecov bot commented Dec 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.92%. Comparing base (6612503) to head (726444b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #789   +/-   ##
=======================================
  Coverage   95.92%   95.92%           
=======================================
  Files          35       35           
  Lines        1251     1252    +1     
=======================================
+ Hits         1200     1201    +1     
  Misses         51       51           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jgillard
Copy link
Contributor Author

jgillard commented Dec 7, 2025

A second approach was to simply change

from django.conf import settings

to

from auditlog.conf import settings

inside auditlog/__init__.py, but I don't understand the implications of this as well, but will change to this approach that avoids the duplication of the default value if that's preferred.

Copy link
Member

@2ykwang 2ykwang left a comment

Choose a reason for hiding this comment

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

I've confirmed this fix resolves the issue!
One minor concern with the first approach: the default value would be managed in two places, which increases maintenance overhead.
In my opinion, the second option might be better. Since settings is conventionally associated with django.conf.settings, using an alias could help avoid confusion:

from auditlog.conf import settings as auditlog_settings

What do you think?

@jgillard

@jgillard
Copy link
Contributor Author

Thanks for taking a look! I agree about the duplication. How confident are you in the alternative approach? I'm not a regular package contributor and I would hate for that change to cause someone an issue downstream. I just don't know the implications of that change, so was hoping for someone with Django package experience to ok it.

@2ykwang
Copy link
Member

2ykwang commented Dec 11, 2025

@hramezani do you have any other ideas on this?

@hramezani
Copy link
Member

Thanks @jgillard for the fix. the current approach LGTM

@2ykwang please merge the PR and make the patch release

@2ykwang 2ykwang added this to the 3.4.1 milestone Dec 12, 2025
@2ykwang 2ykwang merged commit dc63671 into jazzband:master Dec 12, 2025
15 checks passed
@2ykwang 2ykwang mentioned this pull request Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: 'Settings' object has no attribute 'AUDITLOG_LOGENTRY_MODEL'

3 participants