Skip to content

feat(Data Modeling, Files): Add files api to data modeling with /retrieve and /list#2647

Open
haakonvt wants to merge 11 commits into
masterfrom
add-files-api-to-data-modeling
Open

feat(Data Modeling, Files): Add files api to data modeling with /retrieve and /list#2647
haakonvt wants to merge 11 commits into
masterfrom
add-files-api-to-data-modeling

Conversation

@haakonvt
Copy link
Copy Markdown
Contributor

This is the first of 3 or 4 parts, adding a "Data Modeling specific Files API interface" to the SDK that should significantly reduce the current friction.

In this part 1 I've added:

  • New files API to to client.data_modeling
  • Added the full interface (currently raising NotImplemented)
  • Code to guarantee and handle only file nodes are fetched
  • Some needed updates to the sync codegen scripts
  • Tests

@haakonvt haakonvt requested review from a team as code owners May 26, 2026 13:31
self,
nodes: NodeId | tuple[str, str],
*,
source: View | ViewId | tuple[str, str, str] = COGNITE_FILE_VIEW_ID,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note for reviewer: ViewIds are immutable so they are fine to use as default args

Copy link
Copy Markdown
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 introduces the DataModelingFilesAPI (and its auto-generated sync counterpart) to support retrieving and listing file nodes within the data modeling framework. It also adds a drop_source method to Node instances to remove a source and its properties, restoring quick property access when a single source remains. Feedback on the changes highlights a bug in drop_source where dropping the last remaining source leaves a stale property lookup reference, a style guide violation where assert_never is used on user-supplied input instead of raising a descriptive TypeError, and a request to add a test assertion to verify that quick property access is disabled when no sources remain.

Comment thread cognite/client/data_classes/data_modeling/instances.py Outdated
Comment thread cognite/client/_api/data_modeling/files.py Outdated
@haakonvt haakonvt force-pushed the add-files-api-to-data-modeling branch 2 times, most recently from 524fc7c to 9328c32 Compare May 26, 2026 14:01
@haakonvt haakonvt force-pushed the add-files-api-to-data-modeling branch from 9328c32 to a09f5dd Compare May 26, 2026 14:06
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.08%. Comparing base (8f0c3e3) to head (a09f5dd).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2647      +/-   ##
==========================================
+ Coverage   93.05%   93.08%   +0.02%     
==========================================
  Files         486      489       +3     
  Lines       49671    49879     +208     
==========================================
+ Hits        46221    46428     +207     
- Misses       3450     3451       +1     
Files with missing lines Coverage Δ
cognite/client/_api/data_modeling/__init__.py 100.00% <100.00%> (ø)
cognite/client/_api/data_modeling/files.py 100.00% <100.00%> (ø)
cognite/client/_api/files.py 93.92% <ø> (ø)
cognite/client/_sync_api/data_modeling/__init__.py 100.00% <100.00%> (ø)
cognite/client/_sync_api/data_modeling/files.py 100.00% <100.00%> (ø)
cognite/client/_sync_api/files.py 100.00% <ø> (ø)
...ite/client/data_classes/data_modeling/instances.py 91.54% <100.00%> (+0.41%) ⬆️
cognite/client/testing.py 100.00% <100.00%> (ø)
...sts_unit/test_api/test_data_modeling/test_files.py 100.00% <100.00%> (ø)
...st_data_classes/test_data_models/test_instances.py 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

# User has passed a custom source, we include CogniteFile source to guarantee only file nodes
# are returned. We will later strip them (hence the 'True' flag) to avoid returning nodes with
# properties from multiple sources as they are very annoying to work with in the SDK.
return [source_as_id, COGNITE_FILE_VIEW_ID], True
Copy link
Copy Markdown
Contributor

@polomani polomani May 29, 2026

Choose a reason for hiding this comment

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

nit: can we document the return tuple type? hard to say what this True bool means here..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What more do you need 😂

Image

Comment on lines +134 to +135
sources, strip = _resolve_source(source)
result = await self._cognite_client.data_modeling.instances.retrieve_nodes(nodes=nodes, sources=sources) # type: ignore[arg-type]
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.

can _resolve_source() return Sequence[ViewId] so we get rid of type ignore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I’ll widen what retrieve_nodes accept 👍

)
if strip:
for node in results:
node.drop_source(COGNITE_FILE_VIEW_ID)
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.

😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is strip a bad word? 😆

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