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

Fails on reverse oneToOne relationship

Open jasonfarkas opened this issue 2 years ago • 2 comments

I have s.t like

class ModelA(SoftDeleteModel): 
   ...

class ModelB(SoftDeleteModel):
  model_a = models.OneToOneField(to=ModelA, on_delete=models.SET_NULL)

when I attempt to delete an instance of model a from the admin. It fails saying 'ModelA' object has no attribute '.all()' this is b/c it is hitting this line https://github.com/scoursen/django-softdelete/blob/e9d6ee1fe96abbae40ee79e4ade22fadae4849f5/softdelete/models.py#L253 instead of realizing that it is a reverse oneToOne field.

jasonfarkas avatar Dec 09 '22 18:12 jasonfarkas

Similar issue for me, trying to delete instance of model a, it throws RelatedObjectDoesNotExist: A has no b, because I don't have any ModelB instance pointing to the deleted model a instance.

lidorkook avatar Dec 29 '22 14:12 lidorkook

@lidorkook your issue is not the same as the one @jasonfarkas has reported. I believe your problem has been solved, but the fix is not yet released to PyPI. Did you try installing directly from GitHub in order to see if the problem is still there?

decibyte avatar Jan 10 '23 17:01 decibyte