Skip to content

feat(SyntheticTimeSeries): only allow Python identifiers as variable names - #2762

Open
MortGron wants to merge 2 commits into
masterfrom
only-valid-python-identifiers-as-variable-names-in-synthetic-time-series-queries
Open

feat(SyntheticTimeSeries): only allow Python identifiers as variable names#2762
MortGron wants to merge 2 commits into
masterfrom
only-valid-python-identifiers-as-variable-names-in-synthetic-time-series-queries

Conversation

@MortGron

@MortGron MortGron commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

If you try to make an expression like "a-b-1", with the variable substitution {"a-b": "ts_ex_id"}, it will currently fail with an unclear error.
If you make the expression "a - a/b", with the variable subsutiotn {"a": "ts_ex_id_1", "a/b": "ts_ex_id_2"}, it will not fail, but incorrectly be translated to the expression "ts{externalId:'ts_ex_id_1'} - ts{externalId:'ts_ex_id_1'}/b".

The safest thing to do seems like dissallowing variable names that are not Python identifiers, or we might end up with variable names that also contains mathemtical operators.

This PR explicitly fobids variable names that are not Python identifiers with a clear error message.

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • The PR title follows the Conventional Commit spec.

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.75%. Comparing base (b99af78) to head (75c3075).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2762      +/-   ##
==========================================
- Coverage   93.78%   93.75%   -0.03%     
==========================================
  Files         513      513              
  Lines       52445    52449       +4     
==========================================
- Hits        49184    49176       -8     
- Misses       3261     3273      +12     
Files with missing lines Coverage Δ
cognite/client/_api/synthetic_time_series.py 96.03% <100.00%> (+0.06%) ⬆️
cognite/client/_sync_api/synthetic_time_series.py 100.00% <ø> (ø)
.../tests_unit/test_api/test_synthetic_time_series.py 97.63% <100.00%> (+0.03%) ⬆️

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

@MortGron
MortGron marked this pull request as ready for review August 11, 2026 11:15
@MortGron
MortGron requested review from a team as code owners August 11, 2026 11:15

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces a validation check in the synthetic time series expression builder to ensure that variable names are valid Python identifiers, raising a ValueError otherwise. A corresponding unit test has been added to verify this behavior, and the auto-generated synchronous API file has been updated. There are no review comments, and I have no further feedback to provide.

@haakonvt

Copy link
Copy Markdown
Contributor

This seems to me like a breaking change. I'm happy to let it through regardless though - as synthetic TS see very little use, but lets get some more eyes on this (perhaps a slack thread in #topic-sdk)

@MortGron

Copy link
Copy Markdown
Contributor Author

This seems to me like a breaking change. I'm happy to let it through regardless though - as synthetic TS see very little use, but lets get some more eyes on this (perhaps a slack thread in #topic-sdk)

I do not have any urgent need for this, so it can wait to next major release. The non-breaking bug fix part of this is in #2766.

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