Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch EcephysSession from SLIMS #38

Merged
merged 17 commits into from
Oct 4, 2024
Merged
9 changes: 5 additions & 4 deletions src/aind_slims_api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import logging
from copy import deepcopy
from functools import lru_cache
from typing import Any, Optional, Type, TypeVar
from typing import Any, Optional, Type, TypeVar, List

from pydantic import ValidationError
from requests import Response
Expand Down Expand Up @@ -127,7 +127,7 @@ def fetch_models(
start: Optional[int] = None,
end: Optional[int] = None,
**kwargs,
) -> list[SlimsBaseModelTypeVar]:
) -> List[SlimsBaseModelTypeVar]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super trivial, and I could be wrong but isn't it now preferred to use list over typing.List?

Copy link
Contributor Author

@mekhlakapoor mekhlakapoor Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, since the slims-api requires 3.10 and up, we can use the generic types

"""Fetch records from SLIMS and return them as SlimsBaseModel objects.

Returns
Expand All @@ -143,6 +143,7 @@ def fetch_models(
"""
resolved_kwargs = deepcopy(model._base_fetch_filters)
logger.debug("Resolved kwargs: %s", resolved_kwargs)

if isinstance(sort, str):
sort = [sort]

Expand All @@ -160,7 +161,7 @@ def fetch_models(
sort=resolved_sort,
start=start,
end=end,
**resolved_kwargs
**resolved_kwargs,
)
return self._validate_models(model, response)

Expand Down Expand Up @@ -189,7 +190,7 @@ def fetch_model(
if len(records) > 0:
logger.debug(f"Found {len(records)} records for {model}.")
if len(records) < 1:
raise SlimsRecordNotFound("No record found.")
raise SlimsRecordNotFound(f"No record found for {model} with {args}.")
return records[0]

@staticmethod
Expand Down
Loading
Loading