Skip to content

Commit

Permalink
[pre-commit.ci] Apply automatic pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Nov 11, 2024
1 parent 1510115 commit e8c95c9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
16 changes: 6 additions & 10 deletions conda-store-server/conda_store_server/_internal/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@ class CondaChannel(Base):
name = Column(Unicode(255), unique=True, nullable=False)
last_update = Column(DateTime)

# The conda_package table also gets updated during an environment build. It is
# The conda_package table also gets updated during an environment build. It is
# possible for an entry to be inserted into the table between the step where
# existing package keys are computed and the bulk insert is executed. This will
# cause the bulk update to fail with an IntegrityError (eg. in postrgres this is a
# psycopg2.errors.UniqueViolation error). In this case, we'll want to retry updating
# cause the bulk update to fail with an IntegrityError (eg. in postrgres this is a
# psycopg2.errors.UniqueViolation error). In this case, we'll want to retry updating
# the conda packages
@utils.retry_on_errors(allowed_retries=1, on_errors=(IntegrityError), logger=logger)
def update_conda_packages(self, db, repodata, architecture):
Expand Down Expand Up @@ -529,7 +529,7 @@ def update_conda_packages(self, db, repodata, architecture):
except Exception as e:
db.rollback()
raise e

logger.info("insert packages done")

def update_conda_package_builds(self, db, repodata, architecture):
Expand Down Expand Up @@ -623,12 +623,8 @@ def update_conda_package_builds(self, db, repodata, architecture):
CondaPackage.version == p_version,
)
)
all_parent_packages = (
db.query(CondaPackage).filter(or_(*statements)).all()
)
all_parent_packages = {
(_.name, _.version): _ for _ in all_parent_packages
}
all_parent_packages = db.query(CondaPackage).filter(or_(*statements)).all()
all_parent_packages = {(_.name, _.version): _ for _ in all_parent_packages}
logger.info(f"parent packages retrieved : {len(all_parent_packages)} ")

for p_name, p_version in subset_keys:
Expand Down
6 changes: 4 additions & 2 deletions conda-store-server/conda_store_server/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# license that can be found in the LICENSE file.

import contextlib
import functools
import hashlib
import json
import os
Expand All @@ -11,7 +12,6 @@
import subprocess
import sys
import time
import functools
from typing import AnyStr

from filelock import FileLock
Expand Down Expand Up @@ -195,7 +195,7 @@ def decorator_retry(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
num_retries = 0
while num_retries <= allowed_retries:
while num_retries <= allowed_retries:
try:
result = func(*args, **kwargs)
except on_errors as e:
Expand All @@ -207,5 +207,7 @@ def wrapper(*args, **kwargs):
else:
return result
return result

return wrapper

return decorator_retry
17 changes: 9 additions & 8 deletions conda-store-server/tests/_internal/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# license that can be found in the LICENSE file.

import pytest

from conda_store_server._internal.utils import disk_usage, du, retry_on_errors

# TODO: Add tests for the other functions in utils.py
Expand Down Expand Up @@ -43,45 +44,45 @@ class MyTestException(Exception):


def test_retry_on_error():
class MyTestClass():
class MyTestClass:
def __init__(self):
self.called = 0

@retry_on_errors(allowed_retries=1, on_errors=(MyTestException))
def raise_my_test_exception(self):
self.called += 1
raise MyTestException

tc = MyTestClass()

with pytest.raises(MyTestException):
tc.raise_my_test_exception()

assert tc.called == 2


def test_retry_on_not_covered_error():
class MyTestClass():
class MyTestClass:
def __init__(self):
self.called = 0

@retry_on_errors(allowed_retries=1, on_errors=(IndexError))
def raise_my_test_exception(self):
self.called += 1
raise MyTestException

tc = MyTestClass()

with pytest.raises(MyTestException):
tc.raise_my_test_exception()

assert tc.called == 1


def test_retry_no_error():
@retry_on_errors(allowed_retries=1, on_errors=(MyTestException))
def test_function():
return 1

result = test_function()
assert result == 1

0 comments on commit e8c95c9

Please sign in to comment.