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 for None values in prefetch when fk_id==0 #1055

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

konchunas
Copy link

Description

This PR fixes a bug with prefetch_related not actually being prefetched for entries with fk_id==0.
It happened because getattr returned 0 which is interpreted as False for if condition check.

Motivation and Context

I have a table where foreign key id = 0 is a valid value.
Somehow prefetch_related always sets fk_id to None and fk to NoneAwaitable for such records.

How Has This Been Tested?

My project runs on Postgres and It works well. It doesn't break anything else.
I've made a simplest test for this case.
The change doesn't affect other tests, but I only ran make test

Checklist:

  • My code follows the code style of this project. (NOT SURE)
  • 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.

tortoise/backends/base/executor.py Outdated Show resolved Hide resolved
Co-authored-by: Andrey Shpak <insspb@users.noreply.github.com>
long2ice
long2ice previously approved these changes Jul 1, 2022
CHANGELOG.rst Outdated
@@ -8,6 +8,12 @@ Changelog

0.18
====
0.18.3
Copy link
Member

Choose a reason for hiding this comment

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

Please add in 0.19.2

Copy link
Author

Choose a reason for hiding this comment

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

Done, thank you

@abondar
Copy link
Member

abondar commented Jun 2, 2024

@konchunas Hi!

Sorry this PR got forgotten

Could you please rebase on fresh develop and move it to new changelog section (0.21.4)?

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