Skip to content

feat(alpha): record view CRUD support#2722

Open
polomani wants to merge 7 commits into
masterfrom
record-views
Open

feat(alpha): record view CRUD support#2722
polomani wants to merge 7 commits into
masterfrom
record-views

Conversation

@polomani

@polomani polomani commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Description

Added RecordViewApply for user to be able to create a record view, also a usedFor property for the /list method, so it is possible to filter record/non-record views. The output (read) type only gained an optional property "stream_id"

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • The PR title follows the Conventional Commit spec.

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.52055% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.66%. Comparing base (0744eb7) to head (e6b1a54).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
cognite/client/data_classes/data_modeling/views.py 83.09% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2722      +/-   ##
==========================================
- Coverage   93.70%   93.66%   -0.05%     
==========================================
  Files         504      504              
  Lines       51112    51317     +205     
==========================================
+ Hits        47897    48067     +170     
- Misses       3215     3250      +35     
Files with missing lines Coverage Δ
cognite/client/_api/data_modeling/views.py 98.50% <100.00%> (+0.46%) ⬆️
cognite/client/_sync_api/data_modeling/views.py 100.00% <100.00%> (ø)
...nite/client/data_classes/data_modeling/__init__.py 100.00% <ø> (ø)
...sts_unit/test_api/test_data_modeling/test_views.py 100.00% <100.00%> (ø)
...t/test_data_classes/test_data_models/test_views.py 100.00% <100.00%> (ø)
cognite/client/data_classes/data_modeling/views.py 91.46% <83.09%> (-1.54%) ⬇️

... and 10 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.

@polomani polomani changed the title feat(alpha): record view CRUD support WIP feat(alpha): record view CRUD suppor Jul 15, 2026
@polomani polomani changed the title feat(alpha): record view CRUD suppor feat(alpha): record view CRUD support Jul 15, 2026
@polomani

Copy link
Copy Markdown
Contributor Author

/gemini review

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

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.

Code Review

This pull request introduces support for record-backed views (an alpha feature) by adding the RecordViewApply class, updating the ViewsAPI to handle record views with appropriate alpha headers and warnings, and adding conversion methods like as_record_view_apply. The review feedback highlights several critical improvements: handling potential generator consumption and dictionary inputs in ViewsAPI.apply, adding validation for properties and stream count in RecordViewApply, using is_record_view consistently, and updating as_write to support polymorphic delegation for record views.

Comment thread cognite/client/_api/data_modeling/views.py Outdated
self.name = name
self.filter = filter
self.implements: list[ViewId] = implements or []
self.properties = properties

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.

high

The docstring states that only mapped properties (no connections) are supported and a TypeError is raised if any other property type is passed. However, the implementation does not perform this validation. We should add a check in __init__ to enforce this constraint.

Suggested change
self.properties = properties
if properties:
for k, v in properties.items():
if not isinstance(v, MappedPropertyApply):
raise TypeError(f'Property {k!r} must be of type MappedPropertyApply, got {type(v)}')
self.properties = properties
References
  1. Provide meaningful error messages, for example 'got type foo, expected type bar'. (link)

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 don't think we do this usually?

Comment thread cognite/client/data_classes/data_modeling/views.py
Comment thread cognite/client/data_classes/data_modeling/views.py Outdated
Comment thread cognite/client/data_classes/data_modeling/views.py
@polomani
polomani marked this pull request as ready for review July 15, 2026 12:53
@polomani
polomani requested review from a team as code owners July 15, 2026 12:53

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

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.

Code Review

This pull request introduces support for record-backed views (an alpha feature) in the Cognite Python SDK, adding the RecordViewApply class, updating the sync and async ViewsAPI to handle record views with appropriate alpha headers and warnings, and extending the View class with record-specific helper methods. The review feedback highlights several improvement opportunities, including resolving a potential generator exhaustion bug in ViewsAPI.apply, adding runtime validation for properties in RecordViewApply, and strengthening the robustness of record-view checks and error handling.

Comment thread cognite/client/_api/data_modeling/views.py
Comment thread cognite/client/data_classes/data_modeling/views.py
Comment thread cognite/client/data_classes/data_modeling/views.py Outdated
Comment thread cognite/client/data_classes/data_modeling/views.py Outdated

@haakonvt haakonvt left a comment

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.

Mostly LGTM, a few nit:

Comment thread cognite/client/_api/data_modeling/views.py Outdated
Comment thread cognite/client/_api/data_modeling/views.py Outdated
Comment thread cognite/client/data_classes/data_modeling/views.py Outdated

async def apply(self, view: ViewApply | Sequence[ViewApply]) -> View | ViewList:
async def apply(self, view: ViewApply | RecordViewApply | Sequence[ViewApply | RecordViewApply]) -> View | ViewList:
"""`Create or update (upsert) one or more views <https://api-docs.cognite.com/20230101/tag/Views/operation/ApplyViews>`_.

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.

If the record view apply has a different API doc page, lets add a link to it as well

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.

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.

That is the only link we have atm

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.

Right, it is still "internal", then let's wait 👍

Comment thread cognite/client/_api/data_modeling/views.py Outdated
Comment thread cognite/client/data_classes/data_modeling/views.py Outdated
Comment thread cognite/client/data_classes/data_modeling/views.py Outdated
Comment thread cognite/client/data_classes/data_modeling/views.py Outdated
Comment thread tests/tests_unit/test_data_classes/test_data_models/test_views.py Outdated
Comment thread tests/tests_unit/test_data_classes/test_data_models/test_views.py
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