feat(records): Records API #2616
Conversation
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>
|
Any commit after this message are follow ups to correct claude code first iteration. |
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 Report❌ Patch coverage is 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
🚀 New features to boost your workflow:
|
- 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>
ruff requires imports sorted alphabetically; records must come before space_statistics. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@gemini-code-assist why are you commenting about |
|
Apologies for the confusion. You are correct that |
@gemini-code-assist do we have outdated instructions about this? |
|
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 |
|
Just mentioning this (likely close candidate) #2535 |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
/gemini review |
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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.
| 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)) |
There was a problem hiding this comment.
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
- The style guide requires providing meaningful error messages for fallible operations and ensuring IO/data parsing safety. (link)
| "streams/[^/]+/records", | ||
| "streams/[^/]+/records/upsert", |
There was a problem hiding this comment.
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).
- Upsert is idempotent by definition and should always be retryable.
- 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. - 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.
| "streams/[^/]+/records", | |
| "streams/[^/]+/records/upsert", | |
| "sequences", | |
| "streams", | |
| "simulators", |
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).