Skip to content

fix(tasks): escape task name and cron in generated Flux task option - #741

Merged
karel-rehor merged 2 commits into
influxdata:masterfrom
pcbeingused33:fix/escape-task-option-strings
Dec 4, 2026
Merged

karel-rehor merged 2 commits into
influxdata:masterfrom
pcbeingused33:fix/escape-task-option-strings

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

Escapes the task name and cron that TasksApi.create_task_every / create_task_cron put into the generated Flux option task (the same fix was merged in influxdata/influxdb-client-go#452).

Proposed Changes

TasksApi._create_task builds the Flux script as

option task = {name: "<name>", cron: "<cron>"}

by plain string formatting. A task name containing " or \ produces invalid Flux (the task is rejected by the server), and a name containing ${...} is evaluated as Flux string interpolation instead of being kept literally.

This adds a small _escape_flux_string helper that escapes \, " and ${ (the escapes defined for Flux string literals) and applies it to the name and the cron expression. every is a duration literal, not a string, so it is left unchanged. Names without those characters produce exactly the same Flux as before.

Tests: new unit tests in tests/test_TasksApi.py (TasksApiFluxOptionTest) check the generated option task for a name with ", \ and ${x}, and for a cron with ". They fail on master and pass with this change; they don't need an InfluxDB server.

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional

This change was prepared with the help of an AI coding assistant.

pcbeingused33 and others added 2 commits December 3, 2026 09:52
create_task_every and create_task_cron inserted the task name and cron
expression into the Flux `option task` record without escaping, so a
backslash, double quote or `${` produced invalid Flux or an unintended
string interpolation.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.79%. Comparing base (354d881) to head (0d00d21).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #741      +/-   ##
==========================================
- Coverage   90.83%   90.79%   -0.05%     
==========================================
  Files          41       41              
  Lines        3591     3595       +4     
==========================================
+ Hits         3262     3264       +2     
- Misses        329      331       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@karel-rehor karel-rehor 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.

@pcbeingused33 Thank you for this contribution.

It appears to mirror the go PR452 precisely.

Looks good to me. 🚴 🏁

@karel-rehor
karel-rehor merged commit af36df1 into influxdata:master Dec 4, 2026
14 checks passed
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.

3 participants