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

cannot unpack non-iterable NoneType object with SOFT_DELETE_CASCADE #235

Open
hamidrabedi opened this issue Jul 29, 2023 · 17 comments
Open

Comments

@hamidrabedi
Copy link

I have a parent child model and i want if the parent object got deleted all the children get deleted too (safe delete in my case):

class Review(SafeDeleteModel):
    _safedelete_policy = SOFT_DELETE_CASCADE
    parent = models.ForeignKey(
        'self',
        verbose_name=_("Parent"),
        related_name="children",
        on_delete=models.CASCADE,
        null=True,
        blank=True
    )

and if i delete the parent object this error will be raised:
cannot unpack non-iterable NoneType object
image

@Gagaro
Copy link
Member

Gagaro commented Aug 21, 2023

I just added a test with your model which works: 6cdd3e8

Are you using the last version of safedelete? Do you overwrite the delete method?

@razdva0
Copy link

razdva0 commented Oct 16, 2023

I got the same error on macbook air m1
1.3.2 version

@sazzouz
Copy link

sazzouz commented Oct 24, 2023

Same issue 1.3.2, haven't overwritten any methods, occurring when using the SOFT_DELETE_CASCADE policy. Could it be to do with handling cascaded soft deletions when there are no related objects?

@hamidrabedi
Copy link
Author

hamidrabedi commented Nov 24, 2023

@Gagaro No, it seems like soft delete has problems with children-parent models, also has with django-mptt for tree models. related issue in django-mptt repo:
django-mptt/django-mptt#745

@Gagaro
Copy link
Member

Gagaro commented Nov 27, 2023

I made a test that passed without issue. Are you using your model like that or do you have any idea how to reproduce it?

6cdd3e8#diff-985ae0f484f9a15bfb9b8e016c13075eb6896094ff89516544436dce6c63c4feR297

@hamidrabedi
Copy link
Author

@Gagaro Try deleting from django admin.

@razdva0
Copy link

razdva0 commented Nov 28, 2023

My friend overwritten delete method without return like this:
def delete(self, force_policy=None, **kwargs): super().delete(force_policy, **kwargs)
everything is ok with return

@elihuihms
Copy link

My friend overwritten delete method without return like this: def delete(self, force_policy=None, **kwargs): super().delete(force_policy, **kwargs) everything is ok with return

To expand on @razdva0 answer, I had a model with an overridden delete() method that did not return the tuple returned by SafeDeleteModel.delete(); that's what generated this error. When I captured and returned the tuple the error went away.

@Gagaro
Copy link
Member

Gagaro commented Dec 11, 2023

Thanks for the feedbacks. @hamidrabedi , do you have a delete method which does not return anything?

@hamidrabedi
Copy link
Author

hamidrabedi commented Dec 12, 2023

@Gagaro Yes i do have a delete method, but it calls the super method and returns the result properly:

    def delete(self, *args, **kwargs):
        """
        This method calls the superclass's delete()
        method with the given parameters, and then invalidates
        the cache for the query set's model.
        """
        result = super().delete(**kwargs)
        self.invalidate_cache()
        return result

@Gagaro
Copy link
Member

Gagaro commented Dec 18, 2023

Do you have more parent classes? Do you have a value for result if you try to print it?

@hamidrabedi
Copy link
Author

@Gagaro I found where the problem is, when i try to delete one object normally everything works just fine, but when i call the queryset.delete method in the admin, it raises the error:
image

what gets called in django admin
image

So when you delete one object there is no response returning and it tries to unpack it :
image

@hamidrabedi
Copy link
Author

Do you have more parent classes? Do you have a value for result if you try to print it?

there is no result it raises errors

@Gagaro
Copy link
Member

Gagaro commented Dec 18, 2023

What classes are you inheriting from?

@hamidrabedi
Copy link
Author

@Gagaro
from safedelete.admin import SafeDeleteAdmin
from safedelete.models import SafeDeleteModel

@Gagaro
Copy link
Member

Gagaro commented Jan 8, 2024

It looks good to me. Could you maybe step into all the subsequent delete() to be sure there isn't one which does not return anything?

@hamidrabedi
Copy link
Author

@Gagaro Oh i see, delete got overridden and is returning data.ok i got it.

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

5 participants