I have a Django project using both django-audit-log and django-modeltranslation.
I've been using the audit log for a while without any issues. Now that I introduced translations, a lot of my tests are blowing up. I'm sure the same would have happened if had introduced audit log after translations, so I'm not blaming any of the projects. I just wish they would both work together. But I'm unfortunately not able to find out what the problem is myself.
A weird thing is that this seems to only be a problem during testing. Everything seems to work as expected when running the project normally. But I want my tests to work as well.
$ ./manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
E
======================================================================
ERROR: test_my_model (app.tests.MyModelTestCase)
Test the model.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/path/to/django-auditlog-modeltranslation-testcase/app/tests.py", line 12, in setUp
text='Text of Instance 1'
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/modeltranslation/manager.py", line 381, in create
return super(MultilingualQuerySet, self).create(**kwargs)
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/django/db/models/query.py", line 394, in create
obj.save(force_insert=True, using=self.db)
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/django/db/models/base.py", line 807, in save
force_update=force_update, update_fields=update_fields)
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/django/db/models/base.py", line 847, in save_base
update_fields=update_fields, raw=raw, using=using,
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 193, in send
for receiver in self._live_receivers(sender)
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 193, in <listcomp>
for receiver in self._live_receivers(sender)
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/audit_log/models/managers.py", line 107, in post_save
self.create_log_entry(instance, created and 'I' or 'U')
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/audit_log/models/managers.py", line 102, in create_log_entry
manager.create(action_type = action_type, **attrs)
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/django/db/models/query.py", line 392, in create
obj = self.model(**kwargs)
File "/path/to/django-auditlog-modeltranslation-testcase/.env/lib/python3.5/site-packages/django/db/models/base.py", line 572, in __init__
raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
TypeError: 'text_es' is an invalid keyword argument for this function
----------------------------------------------------------------------
Ran 1 test in 0.003s
FAILED (errors=1)
Destroying test database for alias 'default'...
I found a solution to this problem. It is of course necessary to register the auto generated audit log models for translation as well as the regular models.
I have a Django project using both
django-audit-log
anddjango-modeltranslation
.I've been using the audit log for a while without any issues. Now that I introduced translations, a lot of my tests are blowing up. I'm sure the same would have happened if had introduced audit log after translations, so I'm not blaming any of the projects. I just wish they would both work together. But I'm unfortunately not able to find out what the problem is myself.
A weird thing is that this seems to only be a problem during testing. Everything seems to work as expected when running the project normally. But I want my tests to work as well.I've created another small example Django project to provide a case for this issue.
The complete output from running tests is here:
I've also reported the issue for
django-modeltranslation
.