Skip to content

Commit a965967

Browse files
soapy1pre-commit-ci[bot]peytondmurray
authored
Allow Namespace pydantic model to have a null metadata_ entry (#1063)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Peyton Murray <[email protected]>
1 parent f063a08 commit a965967

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

conda-store-server/conda_store_server/_internal/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def from_list(cls, lst):
8181
class Namespace(BaseModel):
8282
id: int
8383
name: Annotated[str, StringConstraints(pattern=f"^[{ALLOWED_CHARACTERS}]+$")] # noqa: F722
84-
metadata_: Dict[str, Any] = None
84+
metadata_: Optional[Dict[str, Any]] = None
8585
role_mappings: List[NamespaceRoleMapping] = []
8686
model_config = ConfigDict(from_attributes=True)
8787

conda-store-server/tests/_internal/server/views/test_api.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,23 @@ def test_api_list_namespace_auth(testclient, seed_conda_store, authenticate):
175175
assert sorted([_.name for _ in r.data]) == ["default", "namespace1", "namespace2"]
176176

177177

178+
def test_api_list_namespace_including_missing_metadata_(
179+
testclient, seed_namespace_with_edge_cases, authenticate
180+
):
181+
"""Test that a namespace with metadata_ = None can be retrieved.
182+
183+
See https://github.com/conda-incubator/conda-store/issues/1062
184+
for additional context.
185+
"""
186+
response = testclient.get("api/v1/namespace")
187+
response.raise_for_status()
188+
189+
r = schema.APIListNamespace.model_validate(response.json())
190+
assert r.status == schema.APIStatus.OK
191+
namespaces = [_.name for _ in r.data]
192+
assert "namespace_missing_meta" in namespaces
193+
194+
178195
def test_api_get_namespace_unauth(testclient, seed_conda_store):
179196
response = testclient.get("api/v1/namespace/default")
180197
response.raise_for_status()

conda-store-server/tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,18 @@ def alembic_config(conda_store):
417417
return {"file": ini_file}
418418

419419

420+
@pytest.fixture
421+
def seed_namespace_with_edge_cases(db: Session, conda_store):
422+
namespaces = [
423+
orm.Namespace(name="normal_namespace"),
424+
orm.Namespace(name="namespace_missing_meta", metadata_=None),
425+
]
426+
427+
for namespace in namespaces:
428+
db.add(namespace)
429+
db.commit()
430+
431+
420432
def _seed_conda_store(
421433
db: Session,
422434
conda_store,

0 commit comments

Comments
 (0)