Skip to content

[CDF-27148] 🚄Use pydantic classes in InstanceIO#2528

Merged
doctrino merged 7 commits intomainfrom
refactor-instance-io
Feb 17, 2026
Merged

[CDF-27148] 🚄Use pydantic classes in InstanceIO#2528
doctrino merged 7 commits intomainfrom
refactor-instance-io

Conversation

@doctrino
Copy link
Collaborator

Description

Use the new pydantic classes in the InstanceIO

Bump

  • Patch
  • Skip

Changelog

Improved

  • Serialization when working with instances in the data plugin.

@gemini-code-assist
Copy link
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

@doctrino doctrino marked this pull request as ready for review February 17, 2026 08:41
@doctrino doctrino requested review from a team as code owners February 17, 2026 08:41
@doctrino
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors InstanceIO to use new Pydantic classes, which is a great improvement for type safety and code clarity, aligning well with the repository's style guide. The changes are well-implemented across the board, including updates to selectors, commands, and tests. I have one suggestion regarding a naming convention for a constant to ensure full adherence to the style guide.

@github-actions
Copy link

github-actions bot commented Feb 17, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
34386 29515 86% 80% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_instance.py 96% 🟢
cognite_toolkit/_cdf_tk/commands/_purge.py 86% 🟢
cognite_toolkit/_cdf_tk/commands/_upload.py 85% 🟢
cognite_toolkit/_cdf_tk/storageio/_instances.py 82% 🟢
cognite_toolkit/_cdf_tk/storageio/selectors/_instances.py 84% 🟢
cognite_toolkit/_cdf_tk/utils/cdf.py 93% 🟢
TOTAL 88% 🟢

updated for commit: c4287d1 by action🐍

@doctrino doctrino force-pushed the refactor-instance-io branch from 4898446 to 3156551 Compare February 17, 2026 08:45
@doctrino doctrino enabled auto-merge (squash) February 17, 2026 08:45
chunk = InstanceList([])
instance_filter = self._build_instance_filter(selector)
total = 0
for instance in iterate_instances(client=self.client, **selector.as_filter_args()):
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note that as_filter_args seems to be unused as of this change

def items(self) -> InstanceIdCSVList:
return InstanceIdCSVList.read_csv_file(self.datafile)

@lru_cache(maxsize=1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this one should probably be @cached_property since it takes no arguments (and seems like that is usually recommended instead of lru_cache when used with self)


def download_ids(self, selector: InstanceSelector, limit: int | None = None) -> Iterable[list[InstanceId]]:
def download_ids(self, selector: InstanceSelector, limit: int | None = None) -> Iterable[Sequence[InstanceId]]:
# Switch to use pydantic classes once purge has been updated.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this comment have a TODO: prefix?

chunk = InstanceList([])
instance_filter = self._build_instance_filter(selector)
total = 0
for instance in iterate_instances(client=self.client, **selector.as_filter_args()):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same goes for iterate_instances

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch.

def as_id(self) -> ViewId:
return ViewId(space=self.space, external_id=self.external_id, version=self.version)
def as_id(self) -> ViewReference:
return ViewReference(space=self.space, external_id=self.external_id, version=self.version or "latest")
Copy link
Contributor

@Magssch Magssch Feb 17, 2026

Choose a reason for hiding this comment

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

Since self.version can be None it seems like we should account for creating a ViewReferenceNoVersion here conditionally (?), I don't think we handle"latest" as a default version string anywhere?

@codecov
Copy link

codecov bot commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 94.93671% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.83%. Comparing base (da5d8e0) to head (c4287d1).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cognite_toolkit/_cdf_tk/storageio/_instances.py 96.29% 2 Missing ⚠️
..._toolkit/_cdf_tk/storageio/selectors/_instances.py 86.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2528      +/-   ##
==========================================
- Coverage   85.83%   85.83%   -0.01%     
==========================================
  Files         414      414              
  Lines       34409    34386      -23     
==========================================
- Hits        29536    29515      -21     
+ Misses       4873     4871       -2     
Files with missing lines Coverage Δ
...client/resource_classes/data_modeling/_instance.py 95.65% <100.00%> (+1.79%) ⬆️
cognite_toolkit/_cdf_tk/commands/_purge.py 86.27% <100.00%> (ø)
cognite_toolkit/_cdf_tk/commands/_upload.py 84.86% <100.00%> (-0.10%) ⬇️
cognite_toolkit/_cdf_tk/utils/cdf.py 93.22% <100.00%> (+2.74%) ⬆️
cognite_toolkit/_cdf_tk/storageio/_instances.py 82.00% <96.29%> (+3.73%) ⬆️
..._toolkit/_cdf_tk/storageio/selectors/_instances.py 84.21% <86.66%> (-11.67%) ⬇️

... and 2 files with indirect coverage changes

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

@doctrino doctrino requested a review from Magssch February 17, 2026 10:20
@doctrino doctrino merged commit 6c0c0b2 into main Feb 17, 2026
15 checks passed
@doctrino doctrino deleted the refactor-instance-io branch February 17, 2026 12:41
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