Skip to content

Commit b5a160f

Browse files
authored
DOG-6526: Removed system managed properties (#491)
* Removed is_uploaded manual updation * Add test cases and update sdk * Change version
1 parent 3e215b7 commit b5a160f

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ Changes are grouped as follows
1313
- `Security` in case of vulnerabilities.
1414

1515

16+
## 7.10.1
17+
18+
### Fixed
19+
20+
* Removed manual setting of `is_uploaded` property on `CogniteExtractorFileApply` objects during file upload to allow SDK to manage upload status.
21+
22+
1623
## 7.10.0
1724

1825
### Added

cognite/extractorutils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Cognite extractor utils is a Python package that simplifies the development of new extractors.
1717
"""
1818

19-
__version__ = "7.10.0"
19+
__version__ = "7.10.1"
2020
from .base import Extractor
2121

2222
__all__ = ["Extractor"]

cognite/extractorutils/uploader/files.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,6 @@ def upload_file(
520520
else:
521521
self._upload_bytes(size, file, file_meta)
522522

523-
if isinstance(file_meta, CogniteExtractorFileApply):
524-
file_meta.is_uploaded = True
525-
526523
if self.post_upload_function:
527524
try:
528525
self.post_upload_function([file_meta])

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "cognite-extractor-utils"
3-
version = "7.10.0"
3+
version = "7.10.1"
44
description = "Utilities for easier development of extractors for CDF"
55
authors = [
66
{name = "Mathias Lohne", email = "mathias.lohne@cognite.com"}
@@ -15,7 +15,7 @@ classifiers = [
1515
]
1616

1717
dependencies = [
18-
"cognite-sdk>=7.75.2",
18+
"cognite-sdk>=7.90.0",
1919
"prometheus-client>=0.7.0,<=1.0.0",
2020
"arrow>=1.0.0",
2121
"pyyaml>=5.3.0,<7",

tests/tests_unit/test_cdf_upload_queues.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
import time
1717
from datetime import datetime, timezone
1818
from io import BytesIO
19-
from typing import Any
19+
from typing import Any, BinaryIO
2020
from unittest.mock import Mock, patch
2121

2222
from httpx import URL, Request
2323

24-
from cognite.client.data_classes import Event, Row
24+
from cognite.client.data_classes import Event, FileMetadata, Row
25+
from cognite.client.data_classes.data_modeling.extractor_extensions.v1 import (
26+
CogniteExtractorFileApply,
27+
)
28+
from cognite.client.testing import CogniteClientMock
2529
from cognite.extractorutils.uploader import (
2630
EventUploadQueue,
2731
IOFileUploadQueue,
@@ -300,3 +304,40 @@ def test_mock_private_link_upload(MockCogniteClient: Mock) -> None:
300304
response: Request = queue._get_file_upload_request(mock_download_url, mock_stream, len(bytes_))
301305

302306
assert response.url.netloc == base_url.netloc
307+
308+
309+
@patch("cognite.client.CogniteClient")
310+
def test_manually_set_is_uploaded(mock_client: CogniteClientMock) -> None:
311+
mock_client.config.max_workers = 4
312+
313+
queue = IOFileUploadQueue(
314+
cdf_client=mock_client,
315+
max_queue_size=10,
316+
)
317+
318+
file_apply = CogniteExtractorFileApply(
319+
external_id="test-file",
320+
name="test-file.txt",
321+
space="test-space",
322+
)
323+
324+
# Record the initial state of is_uploaded
325+
initial_is_uploaded = file_apply.is_uploaded
326+
327+
def read_file() -> BinaryIO:
328+
return BytesIO(b"test content")
329+
330+
# Mock the upload methods
331+
with patch.object(queue, "_upload_bytes"), patch.object(queue, "_upload_only_metadata") as mock_upload_metadata:
332+
mock_file_metadata = Mock(spec=FileMetadata)
333+
mock_file_metadata.mime_type = "text/plain"
334+
mock_upload_metadata.return_value = (mock_file_metadata, "https://upload.url")
335+
336+
with queue:
337+
queue.add_io_to_upload_queue(file_apply, read_file)
338+
queue.upload()
339+
340+
# Verify that is_uploaded was NOT manually changed by the uploader
341+
assert file_apply.is_uploaded == initial_is_uploaded, (
342+
"is_uploaded should not be manually changed by the uploader, it should be managed by the SDK"
343+
)

0 commit comments

Comments
 (0)