Bug #96300 Iterating over a Django QuerySet using a for loop, it "hangs" on last element
Submitted: 23 Jul 2019 22:34 Modified: 30 May 2021 21:10
Reporter: Christian Matenaers Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:mysql_connector_python-8.0.16-cp37-cp37m OS:MacOS (10.14.5 (18F132))
Assigned to: CPU Architecture:x86
Tags: hangs, iterator

[23 Jul 2019 22:34] Christian Matenaers
Description:
When iterating over a Python (3.7) Django (2.0 - 2.2)  QuerySet, I experience that the iterator hangs on the very last element in the QuerySet.

I have posted details about the issue here: https://stackoverflow.com/questions/57134263/django-paginator-not-responsive-on-last-page

It took me quite a while to find the issue, but I'll explain in the "how to repeat"

How to repeat:
Create a Django ORM model in your DB and add a few records.

Then iterate over the result set like so:

def read_from_db_3():
    res = Skus.objects.filter(status=1)
    for line in res:
        print(line.sku)

You will see that the iterator will continue returning the last element in the list in perpetuity.

This does not happen when you use the .iterator() method, but that may not be an option in certain circumstances where, for example, you rely on a third-party module that doesn't use the iterator and only accepts a QuerySet.
[30 Apr 2021 21:10] MySQL Verification Team
Thank you for the bug report. Apologize for the delay, please check with current release version 8.0.24 if the issue still exist. Thanks in advance.
[1 Jun 2021 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".