Skip to content

Commit

Permalink
Lazily import django.test to reduce import time (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
angusholder authored Apr 26, 2024
1 parent 3cc512e commit 07a5edc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/django_mysql/models/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from django.db import models
from django.db.models.sql.where import ExtraWhere
from django.db.transaction import atomic
from django.test.utils import CaptureQueriesContext
from django.utils.functional import cached_property
from django.utils.translation import gettext as _

Expand Down Expand Up @@ -722,6 +721,9 @@ def can_approx_count(queryset: QuerySetMixin) -> bool:


def pt_visual_explain(queryset: models.QuerySet, display: bool = True) -> str:
# Lazy import improves start time - manage.py wouldn't normally import django.test
from django.test.utils import CaptureQueriesContext

connection = connections[queryset.db]
capturer = CaptureQueriesContext(connection)
with capturer, connection.cursor() as cursor:
Expand Down

0 comments on commit 07a5edc

Please sign in to comment.