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

orm: queryset: Fix circular reference error #4247

Merged
merged 1 commit into from May 15, 2018

Conversation

Projects
None yet
2 participants
@greezybacon
Member

greezybacon commented Apr 19, 2018

In my further development of the ORM, I found this bug. It's a circular reference between the ModelInstanceManager and the QuerySet instances. It prevents the query statement and database resources from being cleaned up automatically when the query leaves scope (ie. function exits) and there are still records to be fetched from the database (for instance, if only the first record of a recordset with multiple rows was fetched).

This fixes an error where the ModelInstanceManager maintained a reference to the QuerySet instance, and the QuerySet instance managed a reference to the ModelInstanceManager instance (if it's the iterator for the query). Because of the circular reference, if the iterator is not exhausted, then the resource is not closed and the query remains open. This wastes memory and prevents some other queries from running after such a situation happens.

This addresses the issue by removing the circular reference between the QuerySet and the ModelInstanceManager.

queryset: Fix circular reference error
This fixes an error where the ModelInstanceManager maintained a reference to
the QuerySet instance, and the QuerySet instance managed a reference to the
ModelInstanceManager instance (if it's the iterator for the query). Because
of the circular reference, if the iterator is not exhausted, then the
resource is not closed and the query remains open. This wastes memory and
prevents some other queries from running after such a situation happens.

This addresses the issue by removing the circular reference between the
QuerySet and the ModelInstanceManager.

@protich protich merged commit 22cb861 into osTicket:develop May 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment