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

Fix bug in tortoise.models.Model When a QuerySet uses the only function and then uses the print function to print the returned result, an AttributeError is generated #1724

Merged
merged 1 commit into from
Sep 29, 2024

Conversation

gck123
Copy link
Contributor

@gck123 gck123 commented Sep 29, 2024

…tion and then uses the print function to print the returned result, an AttributeError is generated

Description

old:

def _get_pk_val(self) -> Any:
        return getattr(self, self._meta.pk_attr)

new:

def _get_pk_val(self) -> Any:
        return getattr(self, self._meta.pk_attr, None)

Motivation and Context

When a QuerySet uses the only function and then uses the print function to print the returned result, an AttributeError is generated
https://github.com/tortoise/tortoise-orm/issues/1723

How Has This Been Tested?

make ci

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.

…tion and then uses the print function to print the returned result, an AttributeError is generated
@gck123 gck123 changed the title Fix bug in tortoise.models.Model When a QuerySet uses the only func… Fix bug in tortoise.models.Model When a QuerySet uses the only function and then uses the print function to print the returned result, an AttributeError is generated Sep 29, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 11091622517

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 89.011%

Totals Coverage Status
Change from base Build 11067278859: 0.0%
Covered Lines: 5965
Relevant Lines: 6586

💛 - Coveralls

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.

4 participants