Skip to content

feat: add contains() operation to QuerySet#2163

Open
seladb wants to merge 5 commits intotortoise:developfrom
seladb:add-contains
Open

feat: add contains() operation to QuerySet#2163
seladb wants to merge 5 commits intotortoise:developfrom
seladb:add-contains

Conversation

@seladb
Copy link
Copy Markdown
Contributor

@seladb seladb commented Apr 1, 2026

Add QuerySet.contains() method for checking if object exists in queryset

Description

Added QuerySet.contains() which checks if a specific model instance exists within a queryset. Implementation includes:

  • QuerySet.contains(obj) method in tortoise/queryset.py that returns a ContainsQuery object
  • ContainsQuery class that extends ExistsQuery and adds filtering by the object's primary key

Motivation and Context

This feature enables checking if a specific model instance belongs to a filtered queryset, useful for membership checks without fetching the full object.

It's also in par with Django API.

How Has This Been Tested?

  • Added test_contains in tests/test_queryset.py covering all cases
  • All existing tests pass

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 1, 2026

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing seladb:add-contains (f0e7e77) with develop (2df46d0)

Open in CodSpeed

@seladb seladb marked this pull request as ready for review April 1, 2026 06:58
@seladb seladb changed the title Add contains() operation to QuerySet feat: Add contains() operation to QuerySet Apr 3, 2026
@seladb
Copy link
Copy Markdown
Contributor Author

seladb commented Apr 3, 2026

@abondar MSSQL tests fail randomly, but shouldn't be related to the changes in this PR

@seladb seladb changed the title feat: Add contains() operation to QuerySet feat: add contains() operation to QuerySet Apr 4, 2026
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.

1 participant