Skip to content

Commit

Permalink
Merge branch 'main' into dev/1.27
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkkul committed Oct 16, 2024
2 parents e537f93 + f366065 commit 7362fc3
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ jobs:
python-version: ${{ matrix.versions.py }}
cache: 'pip' # caching pip dependencies
- name: Login to Docker Hub
if: ${{ github.triggering_actor != 'dependabot[bot]' }}
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKER_USERNAME}}
Expand Down Expand Up @@ -196,6 +197,7 @@ jobs:
python-version: ${{ matrix.versions.py }}
cache: 'pip' # caching pip dependencies
- name: Login to Docker Hub
if: ${{ github.triggering_actor != 'dependabot[bot]' }}
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKER_USERNAME}}
Expand Down Expand Up @@ -246,6 +248,7 @@ jobs:
python-version: "3.11"
cache: 'pip' # caching pip dependencies
- name: Login to Docker Hub
if: ${{ github.triggering_actor != 'dependabot[bot]' }}
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKER_USERNAME}}
Expand Down Expand Up @@ -337,6 +340,7 @@ jobs:
with:
fetch-depth: 0
- name: Login to Docker Hub
if: ${{ github.triggering_actor != 'dependabot[bot]' }}
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKER_USERNAME}}
Expand Down
2 changes: 2 additions & 0 deletions integration_v3/test_backup_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,5 @@ def test_cancel_backup(client: weaviate.WeaviateClient) -> None:
if status_resp.status == BackupStatus.CANCELED:
break
time.sleep(0.1)
status_resp = client.backup.get_create_status(backup_id=backup_id, backend=BACKEND)
assert status_resp.status == BackupStatus.CANCELED
60 changes: 59 additions & 1 deletion mock_tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
)
from weaviate.connect.base import ConnectionParams, ProtocolParams
from weaviate.connect.integrations import _IntegrationConfig
from weaviate.exceptions import UnexpectedStatusCodeError, WeaviateStartUpError
from weaviate.exceptions import (
UnexpectedStatusCodeError,
WeaviateStartUpError,
BackupCanceledError,
)

ACCESS_TOKEN = "HELLO!IamAnAccessToken"
REFRESH_TOKEN = "UseMeToRefreshYourAccessToken"
Expand Down Expand Up @@ -370,3 +374,57 @@ def test_node_with_timeout(

nodes = client.cluster.nodes(output=output)
assert nodes[0].status == "TIMEOUT"


def test_backup_cancel_while_create_and_restore(
weaviate_no_auth_mock: HTTPServer, start_grpc_server: grpc.Server
) -> None:
client = weaviate.connect_to_local(
port=MOCK_PORT,
host=MOCK_IP,
grpc_port=MOCK_PORT_GRPC,
)

backup_id = "id"

weaviate_no_auth_mock.expect_request("/v1/backups/filesystem").respond_with_json(
{
"collections": ["backupTest"],
"status": "STARTED",
"path": "path",
"id": backup_id,
}
)
weaviate_no_auth_mock.expect_request("/v1/backups/filesystem/" + backup_id).respond_with_json(
{
"collections": ["backupTest"],
"status": "CANCELED",
"path": "path",
"id": backup_id,
}
)

weaviate_no_auth_mock.expect_request(
"/v1/backups/filesystem/" + backup_id + "/restore"
).respond_with_json(
{
"collections": ["backupTest"],
"status": "CANCELED",
"path": "path",
"id": backup_id,
}
)

with pytest.raises(BackupCanceledError):
client.backup.create(
backup_id=backup_id,
backend="filesystem",
wait_for_completion=True,
)

with pytest.raises(BackupCanceledError):
client.backup.restore(
backup_id=backup_id,
backend="filesystem",
wait_for_completion=True,
)
8 changes: 4 additions & 4 deletions requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ wheel
importlib_metadata==8.5.0
setuptools_scm
Sphinx>=7.0.0
sphinx-rtd-theme==2.0.0
sphinx-rtd-theme==3.0.1
autodoc-pydantic==2.2.0
importlib_metadata==8.5.0

Expand All @@ -22,21 +22,21 @@ pytest-cov==5.0.0
pytest-asyncio==0.24.0
pytest-benchmark==4.0.0
pytest-profiling==1.7.0
coverage==7.6.1
coverage==7.6.3
pytest-xdist==3.6.1
werkzeug==3.0.4
pytest-httpserver==1.1.0
py-spy==0.3.14

numpy>=1.24.4,<3.0.0
pandas>=2.0.3,<3.0.0
polars>=0.20.26,<1.8.0
polars>=0.20.26,<1.10.0

fastapi>=0.111.0,<1.0.0
flask[async]>=2.0.0,<3.0.0
litestar>=2.0.0,<3.0.0

mypy==1.11.2
mypy==1.12.0
mypy-extensions==1.0.0
tomli==2.0.2
types-protobuf==4.24.0.1
Expand Down
10 changes: 10 additions & 0 deletions weaviate/backup/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
WeaviateUnsupportedFeatureError,
BackupFailedException,
EmptyResponseException,
BackupCanceledError,
)
from weaviate.util import (
_capitalize_first_letter,
Expand Down Expand Up @@ -192,6 +193,10 @@ async def create(
raise BackupFailedException(
f"Backup failed: {create_status} with error: {status.error}"
)
if status.status == BackupStatus.CANCELED:
raise BackupCanceledError(
f"Backup was canceled: {create_status} with error: {status.error}"
)
sleep(1)
return BackupReturn(**create_status)

Expand Down Expand Up @@ -325,6 +330,11 @@ async def restore(
raise BackupFailedException(
f"Backup restore failed: {restore_status} with error: {status.error}"
)
if status.status == BackupStatus.CANCELED:
raise BackupCanceledError(
f"Backup restore canceled: {restore_status} with error: {status.error}"
)

sleep(1)
return BackupReturn(**restore_status)

Expand Down
5 changes: 5 additions & 0 deletions weaviate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ConnectionConfig:
session_pool_connections: int = 20
session_pool_maxsize: int = 100
session_pool_max_retries: int = 3
session_pool_timeout: int = 5

def __post_init__(self) -> None:
if not isinstance(self.session_pool_connections, int):
Expand All @@ -23,6 +24,10 @@ def __post_init__(self) -> None:
raise TypeError(
f"session_pool_max_retries must be {int}, received {type(self.session_pool_max_retries)}"
)
if not isinstance(self.session_pool_timeout, int):
raise TypeError(
f"session_pool_timeout must be {int}, received {type(self.session_pool_timeout)}"
)


# used in v3 only
Expand Down
4 changes: 3 additions & 1 deletion weaviate/connect/v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ def __get_timeout(
timeout = self.timeout_config.query
elif method == "POST" and not is_gql_query:
timeout = self.timeout_config.insert
return Timeout(timeout=5.0, read=timeout)
return Timeout(
timeout=5.0, read=timeout, pool=self.__connection_config.session_pool_timeout
)

async def __send(
self,
Expand Down
7 changes: 7 additions & 0 deletions weaviate/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from json.decoder import JSONDecodeError
from typing import Union, Tuple

import httpx
import requests

Expand Down Expand Up @@ -137,6 +138,12 @@ class BackupFailedError(WeaviateBaseError):
BackupFailedException = BackupFailedError


class BackupCanceledError(WeaviateBaseError):
"""
Backup canceled Exception.
"""


class EmptyResponseError(WeaviateBaseError):
"""
Occurs when an HTTP request unexpectedly returns an empty response
Expand Down
2 changes: 1 addition & 1 deletion weaviate/gql/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __str__(self) -> str:
additional_props: List[str] = []
cls_fields: Tuple[Field, ...] = fields(self.__class__)
for field in cls_fields:
if issubclass(field.type, bool):
if issubclass(field.type, bool): # type: ignore
enabled: bool = getattr(self, field.name)
if enabled:
name = field.name
Expand Down

0 comments on commit 7362fc3

Please sign in to comment.