Skip to content

feat(records): Records API #2616

Open
andersfylling wants to merge 15 commits into
masterfrom
feat/records-api
Open

feat(records): Records API #2616
andersfylling wants to merge 15 commits into
masterfrom
feat/records-api

Conversation

@andersfylling
Copy link
Copy Markdown
Contributor

@andersfylling andersfylling commented May 8, 2026

Implements all 6 endpoints (ingest, upsert, delete, list, sync,
aggregate) for cognite.client.data_modeling.records with full
typed DTOs, async generator for sync(), chunked writes, and the
complete 16-step wiring (testing mocks, docs, doctest registration,
retry classification, sync codegen).

andersfylling and others added 2 commits May 8, 2026 13:18
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements all 6 endpoints (ingest, upsert, delete, list, sync,
aggregate) for cognite.client.data_modeling.records with full
typed DTOs, async generator for sync(), chunked writes, and the
complete 16-step wiring (testing mocks, docs, doctest registration,
retry classification, sync codegen).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@andersfylling andersfylling changed the title feat/records api feat(records): Records API May 8, 2026
@andersfylling
Copy link
Copy Markdown
Contributor Author

Any commit after this message are follow ups to correct claude code first iteration.

andersfylling and others added 2 commits May 8, 2026 14:01
Sphinx autosummary requires the class to be importable via
BUILD_COGNITE_SDK_DOCS block so it can resolve
AsyncCogniteClient.data_modeling.records in the RST directives.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

❌ Patch coverage is 95.57070% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.06%. Comparing base (d8ba283) to head (cebcbf0).

Files with missing lines Patch % Lines
cognite/client/_api/data_modeling/records.py 86.45% 13 Missing ⚠️
cognite/client/utils/_concurrency.py 81.96% 11 Missing ⚠️
...gnite/client/data_classes/data_modeling/records.py 99.20% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2616      +/-   ##
==========================================
+ Coverage   93.04%   93.06%   +0.01%     
==========================================
  Files         486      490       +4     
  Lines       49577    50162     +585     
==========================================
+ Hits        46130    46683     +553     
- Misses       3447     3479      +32     
Files with missing lines Coverage Δ
cognite/client/_api/data_modeling/__init__.py 100.00% <100.00%> (ø)
cognite/client/_cognite_client.py 95.68% <100.00%> (+0.03%) ⬆️
cognite/client/_sync_api/data_modeling/__init__.py 100.00% <100.00%> (ø)
cognite/client/_sync_api/data_modeling/records.py 100.00% <100.00%> (ø)
...nite/client/data_classes/data_modeling/__init__.py 100.00% <100.00%> (ø)
cognite/client/testing.py 100.00% <100.00%> (ø)
cognite/client/utils/_url.py 100.00% <ø> (ø)
...s_unit/test_api/test_data_modeling/test_records.py 100.00% <100.00%> (ø)
tests/tests_unit/test_api_client.py 99.71% <ø> (ø)
tests/tests_unit/test_docstring_examples.py 100.00% <100.00%> (ø)
... and 3 more

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

andersfylling and others added 2 commits May 8, 2026 14:14
- Replace en-dash (–) with hyphen (-) in 4 docstrings (RUF002)
- Remove unused type: ignore [misc] comment in sync records API (mypy)
- Fix docstring quote style from double to single in Literal types (custom-checks)
- Add RecordsAPI to _make_accessors_for_building_docs() so Sphinx can discover data_modeling.records

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@andersfylling andersfylling marked this pull request as ready for review May 11, 2026 08:59
@andersfylling andersfylling requested review from a team as code owners May 11, 2026 08:59
gemini-code-assist[bot]

This comment was marked as outdated.

ruff requires imports sorted alphabetically; records must come before space_statistics.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@haakonvt
Copy link
Copy Markdown
Contributor

@gemini-code-assist why are you commenting about CogniteObject? That is not a class in the SDK.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Apologies for the confusion. You are correct that CogniteObject is not a public class in the SDK. It appears I made a mistake in my previous reference. Thank you for pointing that out.

@haakonvt
Copy link
Copy Markdown
Contributor

Apologies for the confusion. You are correct that CogniteObject is not a public class in the SDK. It appears I made a mistake in my previous reference. Thank you for pointing that out.

@gemini-code-assist do we have outdated instructions about this?

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Apologies for the confusion in our previous interaction. Regarding your question, we do not have outdated instructions in the codebase or the provided context. The mention of CogniteObject was an error on my part during the conversation, and I appreciate you correcting me. The implementation of the Records API follows the standard SDK patterns as outlined in PLAN.md and the implemented files.

@andersfylling andersfylling marked this pull request as draft May 11, 2026 10:12
@haakonvt
Copy link
Copy Markdown
Contributor

Just mentioning this (likely close candidate) #2535

@andersfylling andersfylling marked this pull request as ready for review May 18, 2026 06:47
@andersfylling andersfylling marked this pull request as draft May 18, 2026 06:47
gemini-code-assist[bot]

This comment was marked as outdated.

@andersfylling
Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist[bot]

This comment was marked as resolved.

@andersfylling andersfylling marked this pull request as ready for review May 18, 2026 09:25
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 RecordsAPI to the Data Modeling module, enabling ingestion, upsertion, deletion, listing, syncing, and aggregation of records along with their associated data classes and concurrency configurations. Feedback identifies a bug in the sync method where the initialization cursor is not cleared between pages, a potential StopIteration error when handling empty aggregate specifications, and the incorrect classification of idempotent record operations as non-retryable.

yield SyncRecord._load(item)
if not data["hasNext"]:
break
body["cursor"] = data["nextCursor"]
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 sync loop does not remove initializeCursor from the request body when updating the cursor for subsequent pages. While some APIs might ignore the initialization parameter if a cursor is present, sending both is incorrect and can lead to unexpected behavior or infinite loops if the API prioritizes the initialization parameter.

Suggested change
body["cursor"] = data["nextCursor"]
body["cursor"] = data["nextCursor"]
body.pop("initializeCursor", None)



def _load_aggregate_spec(data: dict[str, Any]) -> AggregateSpec:
key = next(iter(data))
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

Using next(iter(data)) on a dictionary without checking if it is empty will raise a StopIteration exception. This results in a poor error message when parsing malformed or empty aggregate specifications, violating the style guide principle on providing meaningful error messages.

    if not data:
        raise ValueError("Empty aggregate specification")
    key = next(iter(data))
References
  1. The style guide requires providing meaningful error messages for fallible operations and ensuring IO/data parsing safety. (link)

Comment on lines +38 to +39
"streams/[^/]+/records",
"streams/[^/]+/records/upsert",
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

Adding upsert and the base records path to NON_RETRYABLE_CREATE_DELETE_RESOURCE_PATHS prevents the SDK from retrying these operations on transient network or server errors (5xx).

  1. Upsert is idempotent by definition and should always be retryable.
  2. Delete for records is also idempotent (as unknown IDs are ignored) but is made non-retryable here because the regex automatically appends (/delete)? to paths in this list.
  3. Ingest (base path) is safe to retry even if mutable, as a successful first attempt followed by a retry would simply return a 422 (which is not retried further), whereas a transient failure on the first attempt would be correctly recovered.

Following the pattern of the sibling instances API, these should be removed from the non-retryable list.

Suggested change
"streams/[^/]+/records",
"streams/[^/]+/records/upsert",
"sequences",
"streams",
"simulators",

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