Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Changes are grouped as follows
- `Security` in case of vulnerabilities.


## 7.11.0

### Fixed

* Removed manual setting of `is_uploaded` property on `CogniteExtractorFileApply` objects during file upload to allow SDK to manage upload status.


## 7.10.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion cognite/extractorutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Cognite extractor utils is a Python package that simplifies the development of new extractors.
"""

__version__ = "7.10.0"
__version__ = "7.11.0"
from .base import Extractor

__all__ = ["Extractor"]
3 changes: 0 additions & 3 deletions cognite/extractorutils/uploader/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,6 @@ def upload_file(
else:
self._upload_bytes(size, file, file_meta)

if isinstance(file_meta, CogniteExtractorFileApply):
file_meta.is_uploaded = True

if self.post_upload_function:
try:
self.post_upload_function([file_meta])
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cognite-extractor-utils"
version = "7.10.0"
version = "7.11.0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be a patch version, 7.10.1

description = "Utilities for easier development of extractors for CDF"
authors = [
{name = "Mathias Lohne", email = "mathias.lohne@cognite.com"}
Expand All @@ -15,7 +15,7 @@ classifiers = [
]

dependencies = [
"cognite-sdk>=7.75.2",
"cognite-sdk>=7.90.0",
"prometheus-client>=0.7.0,<=1.0.0",
"arrow>=1.0.0",
"pyyaml>=5.3.0,<7",
Expand Down
45 changes: 43 additions & 2 deletions tests/tests_unit/test_cdf_upload_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
import time
from datetime import datetime, timezone
from io import BytesIO
from typing import Any
from typing import Any, BinaryIO
from unittest.mock import Mock, patch

from httpx import URL, Request

from cognite.client.data_classes import Event, Row
from cognite.client.data_classes import Event, FileMetadata, Row
from cognite.client.data_classes.data_modeling.extractor_extensions.v1 import (
CogniteExtractorFileApply,
)
from cognite.client.testing import CogniteClientMock
from cognite.extractorutils.uploader import (
EventUploadQueue,
IOFileUploadQueue,
Expand Down Expand Up @@ -300,3 +304,40 @@ def test_mock_private_link_upload(MockCogniteClient: Mock) -> None:
response: Request = queue._get_file_upload_request(mock_download_url, mock_stream, len(bytes_))

assert response.url.netloc == base_url.netloc


@patch("cognite.client.CogniteClient")
def test_manually_set_is_uploaded(mock_client: CogniteClientMock) -> None:
mock_client.config.max_workers = 4

queue = IOFileUploadQueue(
cdf_client=mock_client,
max_queue_size=10,
)

file_apply = CogniteExtractorFileApply(
external_id="test-file",
name="test-file.txt",
space="test-space",
)

# Record the initial state of is_uploaded
initial_is_uploaded = file_apply.is_uploaded

def read_file() -> BinaryIO:
return BytesIO(b"test content")

# Mock the upload methods
with patch.object(queue, "_upload_bytes"), patch.object(queue, "_upload_only_metadata") as mock_upload_metadata:
mock_file_metadata = Mock(spec=FileMetadata)
mock_file_metadata.mime_type = "text/plain"
mock_upload_metadata.return_value = (mock_file_metadata, "https://upload.url")

with queue:
queue.add_io_to_upload_queue(file_apply, read_file)
queue.upload()

# Verify that is_uploaded was NOT manually changed by the uploader
assert file_apply.is_uploaded == initial_is_uploaded, (
"is_uploaded should not be manually changed by the uploader, it should be managed by the SDK"
)
Loading