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

Query includes softDeleted relations #476

Open
yesyves opened this issue Feb 23, 2021 · 1 comment
Open

Query includes softDeleted relations #476

yesyves opened this issue Feb 23, 2021 · 1 comment

Comments

@yesyves
Copy link

yesyves commented Feb 23, 2021

Problem

I have a model class SemesterReviewer consisting of a User FK and a Semester FK. A query for users based on the SemesterReviewer relation returns objects whose SemesterReviewer relation was previously softDeleted.

Environment

  • Django Model Utils version: 4.1.1
  • Django version: 3.1.6
  • Python version: 3.9.1
  • Other libraries used, if any:

Code examples

Here is a trimmed down example :

class SemesterReviewer(SoftDeletableModel):
    id = models.UUIDField(
        default=uuid.uuid4,
        primary_key=True,
    )
    semester = models.ForeignKey(
        Semester,
        verbose_name=_('Semester'),
    )
    reviewer = models.ForeignKey(
        User,
        verbose_name=_('Reviewer'),
    )

user = User(username='Mike')
user.save()

semester = Semester()
semester.save()

semester_reviewer = SemesterReviewer(
        semester=semester,
        reviewer=user,
    )

semester_reviewer.save()
semester_reviewer.delete()

reviewers = User.objects.filter(semesterreviewer__semester=semester)
print(reviewers)
[<User: Mike>]

Workaround :

reviewers = User.objects.filter(
    semesterreviewer__semester=semester,
    semesterreviewer__is_removed=False,
)
print(reviewers)
[]
@foarsitter
Copy link
Contributor

Related: #364

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

2 participants