django-auditlog icon indicating copy to clipboard operation
django-auditlog copied to clipboard

LogEntry.log_create writes to read-only database

Open jwellner opened this issue 3 years ago • 2 comments

We are using a primary/replica database configuration in our production environment described like here: https://docs.djangoproject.com/en/4.0/topics/db/multi-db/

I have an issue where LogEntry is written to the read-only database. After some research I found the cause of this issue:

https://github.com/jazzband/django-auditlog/blob/master/auditlog/models.py#L70

By setting the database via .using() it omits the database router.

Anybody knows a solutions for this issue? (And why is the database set this way in de the code?)

jwellner avatar Feb 16 '22 12:02 jwellner

We are having the same problem here.

I think the lib could just use self.create(**kwargs). And let the developer decide which database he will write the object to by setting the DATABASE_ROUTERS.

It sounds like a good idea?

I would like to know why the database is configured this way in the code.

fgsamuel avatar Feb 21 '22 20:02 fgsamuel

Could this pull request be useful?

Pull Request 359

fgsamuel avatar Mar 02 '22 16:03 fgsamuel

Fixed in https://github.com/jazzband/django-auditlog/commit/77ef852706ccfa8523f8de98e886fc9097e252d4

hramezani avatar Aug 16 '22 06:08 hramezani