Skip to content

Commit

Permalink
ensure set_embedding_id_to_latest sets the newest (#967)
Browse files Browse the repository at this point in the history
closes lig-1971
- ensure `set_embedding_id_to_latest` actually sets to the latest
  • Loading branch information
japrescott authored Oct 31, 2022
1 parent 19c074a commit 763da1a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lightly/api/api_workflow_upload_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def set_embedding_id_to_latest(self):
self._embeddings_api.get_embeddings_by_dataset_id(
dataset_id=self.dataset_id
)
self.embedding_id = embeddings_on_server[-1].id
if len(embeddings_on_server) == 0:
raise RuntimeError(f"There are no known embeddings for dataset_id {self.dataset_id}.")
# return first entry as the API returns newest first
self.embedding_id = embeddings_on_server[0].id

def get_embedding_by_name(
self, name: str, ignore_suffix: bool = True
Expand Down
4 changes: 2 additions & 2 deletions tests/api_workflow/mocked_api_workflow_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ def __init__(self, api_client):
self.embeddings = [
DatasetEmbeddingData(
id="embedding_id_xyz",
name="embedding_name_xxyyzz",
name="embedding_newest",
is_processed=True,
created_at=0,
created_at=1111111,
),
DatasetEmbeddingData(
id="embedding_id_xyz_2",
Expand Down
6 changes: 6 additions & 0 deletions tests/api_workflow/test_api_workflow_upload_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ def test_upload_comma_filenames(self):

def test_set_embedding_id_default(self):
self.api_workflow_client.set_embedding_id_to_latest()
self.assertEqual(self.api_workflow_client.embedding_id, 'embedding_id_xyz')

def test_set_embedding_id_no_embeddings(self):
self.api_workflow_client._embeddings_api.embeddings = []
with self.assertRaises(RuntimeError):
self.api_workflow_client.set_embedding_id_to_latest()

def test_upload_existing_embedding(self):

Expand Down

0 comments on commit 763da1a

Please sign in to comment.