Conversation
…returns a corrupted routine revision if the revision has a zero valued input in the configuration
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2470 +/- ##
=======================================
Coverage 48.86% 48.86%
=======================================
Files 191 191
Lines 26152 26152
=======================================
+ Hits 12778 12779 +1
+ Misses 13374 13373 -1
🚀 New features to boost your workflow:
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a bug where a routine revision with a zero-valued input would be parsed incorrectly. The change ensures that the presence of the value field is checked instead of its truthiness. A unit test is added to cover this case. My review includes a suggestion to apply a similar fix for timeseries inputs to prevent a potential bug with empty sourceExternalId values, along with a corresponding test case.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses a bug in deserializing simulator routine revisions, specifically when an input has a zero value or a time series has an empty external ID. The fix correctly checks for the presence of keys rather than their truthiness, which is the right approach. The new tests validate this fix effectively. I have one suggestion to further improve the robustness of the deserialization logic by adding an explicit check for ambiguous inputs, which would make the client more resilient.
| is_constant = resource.get("value") | ||
| is_timeseries = resource.get("sourceExternalId") | ||
| type_ = "constant" if is_constant else "timeseries" if is_timeseries else None | ||
| type_ = "constant" if is_constant is not None else "timeseries" if is_timeseries is not None else None |
There was a problem hiding this comment.
The current logic correctly fixes the issue with falsy values. However, it silently gives precedence to value over sourceExternalId if both are present in the input dictionary. This could hide potential issues with the data source. To make the deserialization more robust, it would be better to explicitly check for this ambiguity and raise an error.
| is_constant = resource.get("value") | |
| is_timeseries = resource.get("sourceExternalId") | |
| type_ = "constant" if is_constant else "timeseries" if is_timeseries else None | |
| type_ = "constant" if is_constant is not None else "timeseries" if is_timeseries is not None else None | |
| has_value = resource.get("value") is not None | |
| has_source_external_id = resource.get("sourceExternalId") is not None | |
| if has_value and has_source_external_id: | |
| raise ValueError("Invalid routine input, cannot contain both 'value' and 'sourceExternalId'") | |
| type_ = "constant" if has_value else "timeseries" if has_source_external_id else None |
References
- The style guide recommends graceful error handling with meaningful error messages. The suggested change adds a validation check to prevent silent data misinterpretation and provides a clear error message if an ambiguous input is received. (link)
Description
client.simulators.routines.revisions.list or retrieve no longer returns a corrupted routine revision if the revision has a zero valued input or empty time series external ID in the configuration
Checklist:
If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.