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

adding check for nullity in related models delete #243

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

AllenWang314
Copy link
Contributor

When related models are deleted, the block of code here around models.py:234 gives the error:

File "/workspaces/project/.venv/lib/python3.9/site-packages/safedelete/models.py", line 246, in soft_delete_cascade_policy_action
_, delete_response = res
TypeError: cannot unpack non-iterable NoneType object

Based on the context, seems like this bug comes about because the original object that is being deleted appears in the related_objects(self) function.

      deleted_counter: Counter = Counter()
        for related in related_objects(self):
            if is_safedelete_cls(related.__class__) and not getattr(related, FIELD_NAME):
                res = related.delete(force_policy=SOFT_DELETE, is_cascade=True, **kwargs)
                if res is not None:
                    _, delete_response = res
                    deleted_counter.update(delete_response)

This issue appeared in django = "4.1.7", the latest version of django-safedelete as well as 1.3.3. Python version is Python 3.9.20. This is the exact bug in #235

@Gagaro
Copy link
Member

Gagaro commented Oct 14, 2024

Thanks for the PR 👍

@Gagaro Gagaro merged commit 7e03ff2 into makinacorpus:master Oct 14, 2024
5 checks passed
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

Successfully merging this pull request may close these issues.

2 participants