soynatan / django-easy-audit

Yet another Django audit log app, hopefully the simplest one.
GNU General Public License v3.0
719 stars 178 forks source link

on_delete=CASCADE for related objects causing a `Matching query does not exist error` #287

Open Kop3sh opened 5 months ago

Kop3sh commented 5 months ago

Steps

  1. What version of Python and Django are you using?

    python --version
    Python 3.10.14
    django-admin --version
    4.2.3
  2. What operating system and processor architecture are you using? using docker image python:3.10-slim-bullseye

  3. What did you do? db schema is the following: user model has several related objects (in their str methods reference the user self.user)

e.g.

class User():
   # pass

class Item():
   name = ...
   user = models.OneToOneField('User', related_name="item", on_delete=models.CASCADE,null=True,blank=True)

   def __str__():
      return f'{self.name} for {self.user}'
  1. What did you expect to see?

    • the Item object DELETE Operation is logged and the object is deleted
    • User delete DELETE Operation is not logged although the object itself is deleted
  2. What did you see instead?

Debugging

After debugging I found that the issue results from the pre/post delete signals for the Item object when trying to write CRUD logs for the delete operations (tried to remove easy audit and remove the str method and it worked)