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

Reverse relation still exposes deleted objects #41

Open
decibyte opened this issue Jan 12, 2017 · 3 comments
Open

Reverse relation still exposes deleted objects #41

decibyte opened this issue Jan 12, 2017 · 3 comments

Comments

@decibyte
Copy link
Contributor

decibyte commented Jan 12, 2017

I think I've found a bug, but it might be me doing something wrong.

Have a look at the test case project I created to show what the bug is.

I've created 2 simple models: Parent and Child. Child has a OneToOneField relation to Parent.

If I create one of each -- child relating to parent -- and then delete the child, then the child is still accessible via parent.child.

I would expect this to raise a DoesNotExist, as the child is (soft)deleted.

@natehawkboss
Copy link

Yes, I have the same issue. It is actually causing some problems for me as it was pulling up deleted records in a form and filling it out, but then obviously not explicitly un-deleting the record when it was saved, just updating the deleted record.

@adiTrullion
Copy link

Hey, any idea how to make it work?

@rizkyarlin
Copy link

rizkyarlin commented May 29, 2023

I am currently working on a similar case. For me it's for checking if the children exists in a ReverseManyToOne. Still working on a PoC.

But for OneToOneField, I believe it's a little bit trickier.

For OneToOneField I'm thinking about doing something like:

overwriting the init() of django.db.models.base.Model

to do something like:

            if is_related_object:
              
                if rel_obj is not _DEFERRED:
                    if isinstance(rel_obj, SoftDeleteObject):
                        if rel_obj.deleted_at is not None:
                            raise ObjectDoesNotExist()
                    _setattr(self, field.name, rel_obj)

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

4 participants