Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Kop3sh opened this issue Apr 3, 2024 · 0 comments

Comments

@Kop3sh
Copy link

Kop3sh commented Apr 3, 2024

Steps

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

  2. 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}'
  • when I try to delete the user model from either the admin panel or the API endpoint
  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
  1. What did you see instead?
  • it throws Matching Query Does not exist Exception
  • 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

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)

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

No branches or pull requests

1 participant