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

Unify field names in queryset classes #1751

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

henadzit
Copy link
Contributor

@henadzit henadzit commented Oct 28, 2024

Description

This is a refactoring change.

This PR:

  • Replaces duplicate fields with a single field in AwaitableQuery and its subclasses, e.g. instead of having both _annotations in AwaitableQuery (the parent) and annotations in UpdateQuery (the child), there will be just a single field called _annotations
    • This is mostly a renaming change but I had to update the logic of _make_query slightly because there was logic that relied on having two distinct fields _annotations and annotations.
  • Make most of query fields private to simplify queryset interface
  • Add tests for the cases where the query is modified and reused multiple times

Motivation and Context

When I was debugging the queryset code, it was really hard to understand what is going on because of the fields named almost identically but having different undocumented purposes. Reusing the fields should make the code more readable and easier to debug.

Here's a relevant discussion in another pull request #1748 (comment)

How Has This Been Tested?

  • Tested the package locally with a sample web app
  • Tests

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.

@coveralls
Copy link

coveralls commented Oct 28, 2024

Pull Request Test Coverage Report for Build 11561852158

Details

  • 141 of 146 (96.58%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.006%) to 89.018%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tortoise/queryset.py 141 146 96.58%
Files with Coverage Reduction New Missed Lines %
tortoise/queryset.py 1 94.54%
Totals Coverage Status
Change from base Build 11529966516: -0.006%
Covered Lines: 5981
Relevant Lines: 6604

💛 - Coveralls

@henadzit henadzit changed the title Unify field names in queryset classees Unify field names in queryset classes Oct 28, 2024
@henadzit
Copy link
Contributor Author

henadzit commented Nov 1, 2024

@abondar, would love to hear your feedback on this one!

Copy link
Member

@abondar abondar left a comment

Choose a reason for hiding this comment

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

Yeah, thank you for this refactoring, it really was confusing, but never had time to take it on

@abondar abondar merged commit 9e84736 into tortoise:develop Nov 1, 2024
7 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.

3 participants