Conversation
Using Gemini Code AssistThe 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
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 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. |
|
/gemini review |
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
There was a problem hiding this comment.
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.
cognite/pygen/_core/templates/data_classes_core_cdf_external.py.jinja
Outdated
Show resolved
Hide resolved
| if key_error.args[0] == data["__typename"]: | ||
| raise ValueError(f"Could not find class for type {data['__typename']}") from None | ||
| raise key_error |
There was a problem hiding this comment.
Improved error message, there can be KeyErrors inside the model_validate call as wel
| @no_type_check | ||
| def as_read(self) -> CogniteTimeSeries: |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
This no longer exists, but is the prioritized field when doing retrieves.
| @@ -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, | |||
There was a problem hiding this comment.
Note, it is ok to use dummy values here as this is a mock data generator.
| value_type=cast(Literal["Double"], "DOUBLE"), | ||
| value_type="DOUBLE", |
There was a problem hiding this comment.
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]: |
There was a problem hiding this comment.
The PySDK does not give nice error messages on missing values. Just a KeyError on the first failure.
Description
Reviewer: All code inside
examples/is generated.Adapt the Pygen code base to fit Cognite-SDK v8
Bump
Changelog
Changed
cognite-sdkto v8