Skip to content

Commit

Permalink
Bug wrong encoding when uploading Nordic characters through files API (
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino authored Oct 3, 2023
1 parent 1b91474 commit 4512da3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [6.28.3] - 2023-10-03
### Fixed
- When uploading files as strings using `client.files.upload_bytes` the wrong encoding is used on Windows, which is causing
part of the content to be lost when uploading. This is now fixed.

## [6.28.2] - 2023-10-02
### Fixed
- When cache lookup did not yield a token for `CredentialProvider`s like `OAuthDeviceCode` or `OAuthInteractive`, a
Expand Down
3 changes: 3 additions & 0 deletions cognite/client/_api/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ def upload_bytes(
>>> c = CogniteClient()
>>> res = c.files.upload_bytes(b"some content", name="my_file", asset_ids=[1,2,3])
"""
if isinstance(content, str):
content = content.encode("utf-8")

file_metadata = FileMetadata(
name=name,
external_id=external_id,
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

__version__ = "6.28.2"
__version__ = "6.28.3"
__api_subversion__ = "V20220125"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "cognite-sdk"

version = "6.28.2"
version = "6.28.3"
description = "Cognite Python SDK"
readme = "README.md"
documentation = "https://cognite-sdk-python.readthedocs-hosted.com"
Expand Down
12 changes: 12 additions & 0 deletions tests/tests_integration/test_api/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest

from cognite.client import CogniteClient
from cognite.client.data_classes import (
FileMetadata,
FileMetadataFilter,
Expand Down Expand Up @@ -202,3 +203,14 @@ def test_filter_file_on_geoLocation(self, cognite_client, new_file_with_geoLocat
time.sleep(0.2)
res = cognite_client.files.list(geo_location=geo_location_filter)
assert res[0].geo_location == new_file_with_geoLocation.geo_location

def test_upload_bytes_with_nordic_characters(self, cognite_client: CogniteClient) -> None:
content = "æøåøøøø ååå ææææ"
external_id = "test_upload_bytes_with_nordic_characters"

_ = cognite_client.files.upload_bytes(
content=content, name="nordic_chars.txt", external_id=external_id, overwrite=True
)

retrieved_content = cognite_client.files.download_bytes(external_id=external_id)
assert retrieved_content == content.encode("utf-8")

0 comments on commit 4512da3

Please sign in to comment.