diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a832ab94..905e35198 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [6.24.0] - 2023-09-12 +### Fixed +- Bugfix for `FilesAPI.upload` and `FilesAPI.upload_bytes` not raising an error on file contents upload failure. Now `CogniteFileUploadError` is raised based on upload response. + ## [6.23.0] - 2023-09-08 ### Added - Supporting for deleting constraints and indexes on containers. diff --git a/cognite/client/_api/files.py b/cognite/client/_api/files.py index 0b459fce9..4bb90c596 100644 --- a/cognite/client/_api/files.py +++ b/cognite/client/_api/files.py @@ -31,6 +31,7 @@ LabelFilter, TimestampRange, ) +from cognite.client.exceptions import CogniteFileUploadError from cognite.client.utils._auxiliary import find_duplicates from cognite.client.utils._identifier import Identifier, IdentifierSequence from cognite.client.utils._validation import process_asset_subtree_ids, process_data_set_ids @@ -570,9 +571,15 @@ def upload_bytes( returned_file_metadata = res.json() upload_url = returned_file_metadata["uploadUrl"] headers = {"Content-Type": file_metadata.mime_type} - self._http_client_with_retry.request( + upload_response = self._http_client_with_retry.request( "PUT", upload_url, data=content, timeout=self._config.file_transfer_timeout, headers=headers ) + if not upload_response.ok: + raise CogniteFileUploadError( + message=upload_response.text, + code=upload_response.status_code, + ) + return FileMetadata._load(returned_file_metadata) def retrieve_download_urls( diff --git a/cognite/client/_version.py b/cognite/client/_version.py index 121bfd5a7..f04e4315f 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "6.23.0" +__version__ = "6.24.0" __api_subversion__ = "V20220125" diff --git a/cognite/client/exceptions.py b/cognite/client/exceptions.py index d1a01309c..af8d6054c 100644 --- a/cognite/client/exceptions.py +++ b/cognite/client/exceptions.py @@ -61,6 +61,19 @@ class CogniteReadTimeout(CogniteException): pass +class CogniteFileUploadError(CogniteException): + def __init__( + self, + message: str, + code: int, + ) -> None: + self.message = message + self.code = code + + def __str__(self) -> str: + return f"{self.message} | code: {self.code}" + + class CogniteMultiException(CogniteException): def __init__( self, diff --git a/pyproject.toml b/pyproject.toml index 1fd0ecd22..694284493 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "6.23.0" +version = "6.24.0" description = "Cognite Python SDK" readme = "README.md"