Skip to content

Added DatalabAPIError handling for create_item#86

Merged
ml-evs merged 3 commits intodatalab-org:mainfrom
wuppersaver:main
Mar 19, 2026
Merged

Added DatalabAPIError handling for create_item#86
ml-evs merged 3 commits intodatalab-org:mainfrom
wuppersaver:main

Conversation

@wuppersaver
Copy link
Copy Markdown
Contributor

When creating an item while trying to attach it to a collection, which does not exist, the DatalabAPIError is not handled correctly. Adding this specific error to the except options solved the issue and correctly creates a collection to attach the item to.

Traceback:

resp = client.create_item(item_type=ITEM_TYPE_SAMPLE,item_data=payload, collection_id=collection_id)
  File "~/api_tests/.venv/lib/python3.14/site-packages/datalab_api/utils.py", line 20, in rich_wrapper
    result = method(self, *args, **kwargs)
  File "~/api_tests/.venv/lib/python3.14/site-packages/datalab_api/__init__.py", line 149, in create_item
    collection_immutable_id = self.get_collection(collection_id)[0]["immutable_id"]
                              ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "~/api_tests/.venv/lib/python3.14/site-packages/datalab_api/utils.py", line 20, in rich_wrapper
    result = method(self, *args, **kwargs)
  File "~/api_tests/.venv/lib/python3.14/site-packages/datalab_api/__init__.py", line 421, in get_collection
    collection = self._get(collection_url)
  File "~/api_tests/.venv/lib/python3.14/site-packages/datalab_api/utils.py", line 20, in rich_wrapper
    result = method(self, *args, **kwargs)
  File "~/api_tests/.venv/lib/python3.14/site-packages/datalab_api/_base.py", line 335, in _get
    return self._request("GET", url, **kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "~/api_tests/.venv/lib/python3.14/site-packages/datalab_api/utils.py", line 20, in rich_wrapper
    result = method(self, *args, **kwargs)
  File "~/api_tests/.venv/lib/python3.14/site-packages/datalab_api/_base.py", line 329, in _request
    return self._handle_response(response, url, expected_status)
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/api_tests/.venv/lib/python3.14/site-packages/datalab_api/utils.py", line 20, in rich_wrapper
    result = method(self, *args, **kwargs)
  File "~/api_tests/.venv/lib/python3.14/site-packages/datalab_api/_base.py", line 261, in _handle_response
    raise DatalabAPIError(
    ...<2 lines>...
    )
datalab_api._base.DatalabAPIError: HTTP 404 Not Found at http://localhost:5001/collections/Test_Batch: No matching collection collection_id='Test_Batch' with current authorization.
Full JSON: {'message': "No matching collection collection_id='Test_Batch' with current authorization.", 'status': 'error'}. Please check the URL/endpoint is correct and the resource exists.

When creating an item while trying to attach it to a collection, which does not exist, the DatalabAPIError is not handled correctly.
Adding this specific error to the except options solved the issue and correctly creates a collection to attach the item to.
@wuppersaver wuppersaver requested a review from ml-evs as a code owner March 19, 2026 13:00
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.88%. Comparing base (af9b5b1) to head (369a104).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/datalab_api/__init__.py 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
- Coverage   43.14%   42.88%   -0.26%     
==========================================
  Files           5        5              
  Lines         496      499       +3     
==========================================
  Hits          214      214              
- Misses        282      285       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ml-evs
Copy link
Copy Markdown
Member

ml-evs commented Mar 19, 2026

pre-commit.ci run

@ml-evs
Copy link
Copy Markdown
Member

ml-evs commented Mar 19, 2026

pre-commit.ci autofix

Copy link
Copy Markdown
Member

@ml-evs ml-evs left a comment

Choose a reason for hiding this comment

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

Thanks for this @wuppersaver!

I'll make a minor tweak that makes the linters pass and then merge this.

@ml-evs ml-evs merged commit fb7c06d into datalab-org:main Mar 19, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants