Skip to content

Commit bcd522d

Browse files
authored
HL Python SDK: fix repository create with storage_id (#9704)
* HL Python SDK: fix repository create with storage_id * Fix test
1 parent a9ab184 commit bcd522d

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

clients/python-wrapper/lakefs/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ class RepositoryProperties(LenientNamedTuple):
116116
creation_date: int
117117
default_branch: str
118118
storage_namespace: str
119+
storage_id: str

clients/python-wrapper/lakefs/repository.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ def create(self,
4848
:raise NotAuthorizedException: if user is not authorized to perform this operation
4949
:raise ServerException: for any other errors
5050
"""
51+
storage_id = kwargs.pop("storage_id", None)
5152
repository_creation = lakefs_sdk.RepositoryCreation(name=self._id,
5253
storage_namespace=storage_namespace,
5354
default_branch=default_branch,
54-
sample_data=include_samples)
55+
sample_data=include_samples,
56+
storage_id=storage_id)
5557

5658
def handle_conflict(e: LakeFSException):
5759
if isinstance(e, ConflictException) and exist_ok:

clients/python-wrapper/tests/integration/test_repository.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import uuid
22
import pytest
33

4+
from lakefs.exceptions import BadRequestException
45
import lakefs
56

67
from tests.integration.conftest import _setup_repo, get_storage_namespace
8+
from tests.utests.common import expect_exception_context
79

810
_NUM_PREFIXES = 10
911
_NUM_ELEM_PER_PREFIX = 20
@@ -49,3 +51,18 @@ def test_repositories(storage_namespace):
4951
assert len(repos) == 10
5052
for i, repo in enumerate(repos):
5153
assert repo.properties.id == f"{repo_base_name}{i}"
54+
55+
56+
def test_repository_create_storage_id(storage_namespace):
57+
repo_id = f"test-repo{uuid.uuid4()}"
58+
storage_id = ""
59+
repo = lakefs.repository(repo_id).create(storage_namespace=storage_namespace, storage_id=storage_id)
60+
assert repo.properties.id == repo_id
61+
assert repo.properties.storage_namespace == storage_namespace
62+
assert repo.properties.storage_id == storage_id
63+
64+
def test_repository_create_storage_id_invalid_value(storage_namespace):
65+
repo_id = f"test-repo{uuid.uuid4()}"
66+
storage_id = "invalidvalue"
67+
with expect_exception_context(BadRequestException):
68+
lakefs.repository(repo_id).create(storage_namespace=storage_namespace, storage_id=storage_id)

clients/python-wrapper/tests/integration/test_sanity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def test_repository_sanity(storage_namespace, setup_repo):
1414
expected_properties = lakefs.RepositoryProperties(id=repo.properties.id,
1515
default_branch=default_branch,
1616
storage_namespace=storage_namespace,
17-
creation_date=repo.properties.creation_date)
17+
creation_date=repo.properties.creation_date,
18+
storage_id="")
1819
assert repo.properties == expected_properties
1920

2021
# Create with allow exists

0 commit comments

Comments
 (0)