Skip to content

[PYG-440] 8️⃣Python-SDK v8#632

Open
doctrino wants to merge 33 commits intomainfrom
pysdk-to-v8
Open

[PYG-440] 8️⃣Python-SDK v8#632
doctrino wants to merge 33 commits intomainfrom
pysdk-to-v8

Conversation

@doctrino
Copy link
Copy Markdown
Contributor

@doctrino doctrino commented Mar 28, 2026

Description

Reviewer: All code inside examples/ is generated.

Adapt the Pygen code base to fit Cognite-SDK v8

  • Some minor changes to mocking of the client in the tests.
  • CogniteObject has been replaced by CogniteResource
  • The DataPoint, TimeSeries, FileMetadata, and Sequence now specifies which parameters are required (before all were optional). This causes some issues when you retrieve these in GraphQL format and convert them to this read format. However, Pygen defines the correct behavior - require the user to include required fields in their GraphQL query. See https://cognite-pygen.readthedocs-hosted.com/en/latest/usage/querying.html#data-classes for more details. Updated the deserialization to give nice error messages.

Bump

  • Patch
  • Minor
  • Skip

Changelog

Changed

  • Updated cognite-sdk to v8

@gemini-code-assist
Copy link
Copy Markdown

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
Copy link
Copy Markdown
Contributor Author

/gemini review

@doctrino doctrino enabled auto-merge (squash) March 28, 2026 09:42
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 28, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
4965 3560 72% 60% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
cognite/pygen/_core/templates/data_classes_core_cdf_external.py.jinja 3% 🟢
cognite/pygen/_query/executor.py 79% 🟢
cognite/pygen/_query/step.py 87% 🟢
cognite/pygen/demo/_solar_apm.py 0% 🟢
cognite/pygen/utils/cdf.py 28% 🟢
cognite/pygen/utils/mock_generator.py 66% 🟢
TOTAL 44% 🟢

updated for commit: 78dbd9b by action🐍

Copy link
Copy Markdown

@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 updates the codebase to support cognite-sdk version 8.0.5, including dependency updates in pyproject.toml. Key changes involve implementing default values for required fields like id, createdTime, and lastUpdatedTime in GraphQL-based data classes to ensure consistency when fields are missing from responses. The PR also refines error handling for missing typenames, updates API calls to use keyword arguments, and adjusts mock generation logic. Feedback suggests using dict.setdefault in templates for more idiomatic and concise default value assignment.

Comment on lines +576 to +578
if key_error.args[0] == data["__typename"]:
raise ValueError(f"Could not find class for type {data['__typename']}") from None
raise key_error
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.

Improved error message, there can be KeyErrors inside the model_validate call as wel

Comment on lines +155 to 156
@no_type_check
def as_read(self) -> CogniteTimeSeries:
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.

We do not do type check here as this is handled by the pydantic validation. If any error is raised, then this is expected behavior. See docs: https://cognite-pygen.readthedocs-hosted.com/en/latest/usage/querying.html#data-classes

uniform_index=uniform_index,
include_aggregate_name=include_aggregate_name,
include_granularity_name=include_granularity_name,
column_names="instance_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.

This no longer exists, but is the prioritized field when doing retrieves.

Comment on lines 393 to +403
@@ -398,6 +399,8 @@ def _only_null_values(count: int) -> list[None]:
metadata={
"source": f"Pygen{type(self).__name__}",
},
created_time=0,
last_updated_time=1,
Copy link
Copy Markdown
Contributor Author

@doctrino doctrino Mar 28, 2026

Choose a reason for hiding this comment

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

Note, it is ok to use dummy values here as this is a mock data generator.

Comment on lines -439 to +447
value_type=cast(Literal["Double"], "DOUBLE"),
value_type="DOUBLE",
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.

Bug fixed in the SDK :)

datetime.datetime.fromisoformat(item["timestamp"].replace("Z", "+00:00"))
)
data["datapoints"] = datapoints["items"]
if missing := [name for name in ["id", "isString", "isStep"] if data.get(name) is None]:
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.

The PySDK does not give nice error messages on missing values. Just a KeyError on the first failure.

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.

1 participant