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

Implement latest and earliest methods for a queryset #1754

Merged
merged 7 commits into from
Nov 2, 2024

Conversation

ruitcatarino
Copy link
Contributor

Description

This implements the latest (https://docs.djangoproject.com/en/5.1/ref/models/querysets/#latest) and earliest (https://docs.djangoproject.com/en/5.1/ref/models/querysets/#earliest) methods similar to Django.

Motivation and Context

Like I explained in the issue #1753 I miss these two methods as someone coming from Django.

How Has This Been Tested?

Well I implemented tests to validate the usage of both and ran them with make test. I also did some local testing.

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.

The existing tests are not passing in the develop branch for me. But the new created tests are passing. I'll post the output of my tests here

===================================================================================== short test summary info ======================================================================================
FAILED tests/test_queryset.py::TestQueryset::test_delete - tortoise.exceptions.OperationalError: near "ORDER": syntax error
FAILED tests/test_queryset.py::TestQueryset::test_delete_limit - tortoise.exceptions.OperationalError: near "LIMIT": syntax error
FAILED tests/test_queryset.py::TestQueryset::test_delete_limit_order_by - tortoise.exceptions.OperationalError: near "ORDER": syntax error
FAILED tests/test_update.py::TestUpdate::test_update_with_limit_ordering - tortoise.exceptions.OperationalError: near "ORDER": syntax error
ERROR tests/test_default.py
ERROR tests/test_two_databases.py
4 failed, 1134 passed, 67 skipped, 4 xfailed, 2 errors in 36.45s

:params field_name: The field name to order by.
"""
queryset = self._clone()
if not (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add few test about passing related fields there?
Like related_model__pub_date

I understand that it is not a prime usecase for that, but if we are supporting that behaviour - would be nice to have it covered

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added more tests to increase coverage, including testing the use of related fields tests/test_latest_earliest.py

@coveralls
Copy link

coveralls commented Nov 1, 2024

Pull Request Test Coverage Report for Build 11637250951

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 36 of 36 (100.0%) changed or added relevant lines in 2 files are covered.
  • 50 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.05%) to 89.069%

Files with Coverage Reduction New Missed Lines %
tortoise/backends/mssql/executor.py 1 94.12%
tortoise/backends/sqlite/executor.py 5 77.14%
tortoise/fields/data.py 13 94.29%
tortoise/queryset.py 31 94.73%
Totals Coverage Status
Change from base Build 11529966516: 0.05%
Covered Lines: 6012
Relevant Lines: 6636

💛 - Coveralls

@abondar abondar merged commit 0f92aa3 into tortoise:develop Nov 2, 2024
7 checks passed
@ruitcatarino ruitcatarino deleted the implement-latest-earliest branch November 2, 2024 11:05
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.

3 participants