Skip to content

Commit 4be8678

Browse files
committed
do not close connections in sync_to_async
1 parent 4a46ace commit 4be8678

File tree

79 files changed

+104
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+104
-97
lines changed

codecov/db/__init__.py

-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import logging
22

3-
from asgiref.sync import SyncToAsync
43
from django.conf import settings
5-
from django.db import close_old_connections
64
from django.db.models import Field, Lookup
75

86
log = logging.getLogger(__name__)
@@ -69,19 +67,3 @@ def as_sql(self, compiler, connection):
6967
rhs, rhs_params = self.process_rhs(compiler, connection)
7068
params = tuple(lhs_params) + tuple(rhs_params)
7169
return "%s is not %s" % (lhs, rhs), params
72-
73-
74-
class DatabaseSyncToAsync(SyncToAsync):
75-
"""
76-
SyncToAsync version that cleans up old database connections.
77-
"""
78-
79-
def thread_handler(self, loop, *args, **kwargs):
80-
close_old_connections()
81-
try:
82-
return super().thread_handler(loop, *args, **kwargs)
83-
finally:
84-
close_old_connections()
85-
86-
87-
sync_to_async = DatabaseSyncToAsync

codecov_auth/commands/owner/interactors/cancel_trial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from asgiref.sync import sync_to_async
12
from shared.plan.service import PlanService
23

34
from codecov.commands.base import BaseInteractor
45
from codecov.commands.exceptions import Unauthorized, ValidationError
5-
from codecov.db import sync_to_async
66
from codecov_auth.helpers import current_user_part_of_org
77
from codecov_auth.models import Owner
88

codecov_auth/commands/owner/interactors/create_api_token.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
24
from codecov.commands.exceptions import Unauthenticated, ValidationError
3-
from codecov.db import sync_to_async
45
from codecov_auth.models import Session
56

67

codecov_auth/commands/owner/interactors/create_stripe_setup_intent.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import logging
22

33
import stripe
4+
from asgiref.sync import sync_to_async
45

56
from codecov.commands.base import BaseInteractor
67
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
7-
from codecov.db import sync_to_async
88
from codecov_auth.helpers import current_user_part_of_org
99
from codecov_auth.models import Owner
1010
from services.billing import BillingService

codecov_auth/commands/owner/interactors/create_user_token.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
24
from codecov.commands.exceptions import Unauthenticated, ValidationError
3-
from codecov.db import sync_to_async
45
from codecov_auth.models import UserToken
56

67

codecov_auth/commands/owner/interactors/delete_session.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from asgiref.sync import sync_to_async
12
from django.contrib.sessions.models import Session as DjangoSession
23

34
from codecov.commands.base import BaseInteractor
45
from codecov.commands.exceptions import Unauthenticated
5-
from codecov.db import sync_to_async
66
from codecov_auth.models import Session
77

88

codecov_auth/commands/owner/interactors/fetch_owner.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
2-
from codecov.db import sync_to_async
34
from codecov_auth.models import Owner
45

56

codecov_auth/commands/owner/interactors/get_org_upload_token.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
24
from codecov.commands.exceptions import Unauthenticated, Unauthorized
3-
from codecov.db import sync_to_async
45
from codecov_auth.helpers import current_user_part_of_org
56
from codecov_auth.models import OrganizationLevelToken
67

codecov_auth/commands/owner/interactors/get_uploads_number_per_user.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import Optional
22

3+
from asgiref.sync import sync_to_async
34
from shared.plan.service import PlanService
45
from shared.upload.utils import query_monthly_coverage_measurements
56

67
from codecov.commands.base import BaseInteractor
7-
from codecov.db import sync_to_async
88
from codecov_auth.models import Owner
99
from services.redis_configuration import get_redis_connection
1010

codecov_auth/commands/owner/interactors/is_syncing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
2-
from codecov.db import sync_to_async
34
from services.refresh import RefreshService
45

56

codecov_auth/commands/owner/interactors/onboard_user.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from asgiref.sync import sync_to_async
12
from django import forms
23

34
from codecov.commands.base import BaseInteractor
45
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
5-
from codecov.db import sync_to_async
66
from codecov_auth.models import OwnerProfile
77

88

codecov_auth/commands/owner/interactors/regenerate_org_upload_token.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import uuid
22

3+
from asgiref.sync import sync_to_async
4+
35
from codecov.commands.base import BaseInteractor
46
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
5-
from codecov.db import sync_to_async
67
from codecov_auth.helpers import current_user_part_of_org
78
from codecov_auth.models import OrganizationLevelToken, Owner
89

codecov_auth/commands/owner/interactors/revoke_user_token.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
24
from codecov.commands.exceptions import Unauthenticated
3-
from codecov.db import sync_to_async
45
from codecov_auth.models import UserToken
56

67

codecov_auth/commands/owner/interactors/save_okta_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from dataclasses import dataclass
22

3+
from asgiref.sync import sync_to_async
34
from shared.django_apps.codecov_auth.models import AccountsUsers, User
45

56
from codecov.commands.base import BaseInteractor
67
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
7-
from codecov.db import sync_to_async
88
from codecov_auth.models import Account, OktaSettings, Owner
99

1010

codecov_auth/commands/owner/interactors/save_terms_agreement.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from dataclasses import dataclass
22
from typing import Any, Optional
33

4+
from asgiref.sync import sync_to_async
45
from django.utils import timezone
56

67
from codecov.commands.base import BaseInteractor
78
from codecov.commands.exceptions import Unauthenticated, ValidationError
8-
from codecov.db import sync_to_async
99
from services.analytics import AnalyticsService
1010

1111

codecov_auth/commands/owner/interactors/set_upload_token_required.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from dataclasses import dataclass
22

3+
from asgiref.sync import sync_to_async
4+
35
from codecov.commands.base import BaseInteractor
46
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
5-
from codecov.db import sync_to_async
67
from codecov_auth.helpers import current_user_part_of_org
78
from codecov_auth.models import Owner
89

codecov_auth/commands/owner/interactors/set_yaml_on_owner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Optional
33

44
import yaml
5+
from asgiref.sync import sync_to_async
56
from shared.django_apps.core.models import Repository
67
from shared.django_apps.utils.model_utils import get_ownerid_if_member
78
from shared.validation.exceptions import InvalidYamlException
@@ -14,7 +15,6 @@
1415
Unauthorized,
1516
ValidationError,
1617
)
17-
from codecov.db import sync_to_async
1818
from codecov_auth.constants import OWNER_YAML_TO_STRING_KEY
1919
from codecov_auth.helpers import current_user_part_of_org
2020
from codecov_auth.models import Owner

codecov_auth/commands/owner/interactors/start_trial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from asgiref.sync import sync_to_async
12
from shared.plan.service import PlanService
23

34
from codecov.commands.base import BaseInteractor
45
from codecov.commands.exceptions import Unauthorized, ValidationError
5-
from codecov.db import sync_to_async
66
from codecov_auth.helpers import current_user_part_of_org
77
from codecov_auth.models import Owner
88

codecov_auth/commands/owner/interactors/store_codecov_metric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import json
22

3+
from asgiref.sync import sync_to_async
34
from shared.django_apps.codecov_metrics.service.codecov_metrics import (
45
UserOnboardingMetricsService,
56
)
67

78
from codecov.commands.base import BaseInteractor
89
from codecov.commands.exceptions import ValidationError
9-
from codecov.db import sync_to_async
1010
from codecov_auth.models import Owner
1111

1212

codecov_auth/commands/owner/interactors/tests/test_delete_session.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import pytest
2+
from asgiref.sync import sync_to_async
23
from django.test import TestCase
34
from shared.django_apps.codecov_auth.tests.factories import OwnerFactory, SessionFactory
45

56
from codecov.commands.exceptions import Unauthenticated
6-
from codecov.db import sync_to_async
77
from codecov_auth.models import DjangoSession, Session
88
from codecov_auth.tests.factories import DjangoSessionFactory
99

codecov_auth/commands/owner/interactors/tests/test_revoke_user_token.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import pytest
2+
from asgiref.sync import sync_to_async
23
from django.test import TestCase
34
from shared.django_apps.codecov_auth.tests.factories import (
45
OwnerFactory,
56
UserTokenFactory,
67
)
78

89
from codecov.commands.exceptions import Unauthenticated
9-
from codecov.db import sync_to_async
1010
from codecov_auth.models import UserToken
1111

1212
from ..revoke_user_token import RevokeUserTokenInteractor

codecov_auth/commands/owner/interactors/tests/test_set_yaml_on_owner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from asgiref.sync import sync_to_async
23
from django.test import TestCase
34
from shared.django_apps.core.tests.factories import OwnerFactory, RepositoryFactory
45

@@ -8,7 +9,6 @@
89
Unauthorized,
910
ValidationError,
1011
)
11-
from codecov.db import sync_to_async
1212

1313
from ..set_yaml_on_owner import SetYamlOnOwnerInteractor
1414

codecov_auth/commands/owner/interactors/trigger_sync.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
24
from codecov.commands.exceptions import Unauthenticated
3-
from codecov.db import sync_to_async
45
from services.refresh import RefreshService
56

67

codecov_auth/commands/owner/interactors/update_default_organization.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import Optional
22

3+
from asgiref.sync import sync_to_async
4+
35
from codecov.commands.base import BaseInteractor
46
from codecov.commands.exceptions import Unauthenticated, ValidationError
5-
from codecov.db import sync_to_async
67
from codecov_auth.models import Owner, OwnerProfile
78
from services.activation import try_auto_activate
89

codecov_auth/commands/owner/interactors/update_profile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from asgiref.sync import sync_to_async
12
from django import forms
23

34
from codecov.commands.base import BaseInteractor
45
from codecov.commands.exceptions import Unauthenticated, ValidationError
5-
from codecov.db import sync_to_async
66

77

88
class UpdateProfileForm(forms.Form):

codecov_auth/commands/owner/interactors/update_self_hosted_settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from dataclasses import dataclass
22

3+
from asgiref.sync import sync_to_async
34
from django.conf import settings
45

56
import services.self_hosted as self_hosted
67
from codecov.commands.base import BaseInteractor
78
from codecov.commands.exceptions import Unauthenticated, ValidationError
8-
from codecov.db import sync_to_async
99

1010

1111
@dataclass

core/commands/branch/interactors/fetch_branch.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
2-
from codecov.db import sync_to_async
34

45

56
class FetchBranchInteractor(BaseInteractor):

core/commands/branch/interactors/fetch_branches.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import Any
22

3+
from asgiref.sync import sync_to_async
34
from django.db.models import OuterRef, Q, QuerySet, Subquery
45
from shared.django_apps.core.models import Repository
56

67
from codecov.commands.base import BaseInteractor
7-
from codecov.db import sync_to_async
88
from core.models import Commit
99

1010

core/commands/commit/interactors/fetch_totals.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
2-
from codecov.db import sync_to_async
34

45

56
class FetchTotalsInteractor(BaseInteractor):

core/commands/commit/interactors/get_commit_errors.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
2-
from codecov.db import sync_to_async
34
from graphql_api.types.enums import CommitErrorCode, CommitErrorGeneralType
45

56

core/commands/commit/interactors/get_final_yaml.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
2-
from codecov.db import sync_to_async
34
from services.yaml import final_commit_yaml
45

56

core/commands/commit/interactors/get_latest_upload_error.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import logging
22
from typing import Optional
33

4+
from asgiref.sync import sync_to_async
5+
46
from codecov.commands.base import BaseInteractor
5-
from codecov.db import sync_to_async
67
from core.models import Commit
78
from reports.models import CommitReport, UploadError
89

core/commands/commit/interactors/get_uploads_number.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
2-
from codecov.db import sync_to_async
34

45

56
class GetUploadsNumberInteractor(BaseInteractor):

core/commands/pull/interactors/fetch_pull_request.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from datetime import datetime, timedelta
22

3+
from asgiref.sync import sync_to_async
34
from shared.django_apps.core.models import Pull, Repository
45

56
from codecov.commands.base import BaseInteractor
6-
from codecov.db import sync_to_async
77
from services.task.task import TaskService
88

99

core/commands/pull/interactors/fetch_pull_requests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
2-
from codecov.db import sync_to_async
34

45

56
class FetchPullRequestsInteractor(BaseInteractor):

core/commands/repository/interactors/activate_measurements.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from asgiref.sync import sync_to_async
12
from django.conf import settings
23

34
from codecov.commands.base import BaseInteractor
45
from codecov.commands.exceptions import ValidationError
5-
from codecov.db import sync_to_async
66
from timeseries.helpers import trigger_backfill
77
from timeseries.models import Dataset, MeasurementName
88

0 commit comments

Comments
 (0)