Skip to content

fix(backend): keep and escape annotation/label values that contain ':' or quotes - #976

Open
SajalDevX wants to merge 9 commits into
kubeflow:mainfrom
SajalDevX:fix/annotation-values-with-colons-and-quotes
Open

SajalDevX wants to merge 9 commits into
kubeflow:mainfrom
SajalDevX:fix/annotation-values-with-colons-and-quotes

Conversation

@SajalDevX

@SajalDevX SajalDevX commented Sep 25, 2026 •

Copy link
Copy Markdown

Fixes #975

What

Annotation (and label) values were changed or broke compilation in two ways:

  1. get_annotation_or_label_from_tag() split the tag on : and put the value back together with "".join(...), so every : in the value disappeared. http://grafana.local:3000/d/abc became http//grafana.local3000/d/abc. This also hit steps_defaults, since it uses the same helper.
  2. _step_config.jinja2 put the raw value inside "...", so a value like {"lr": 0.01} generated a DSL file that fails with SyntaxError.

Changes

  • nbprocessor.py: join the rest of the tag with TAG_SEPARATOR (same as the image: tag handling a few lines below).
  • _step_config.jinja2: render label_value and annotation_value with | tojson so they always end up as valid, escaped string literals. Keys are left as they are, since the validators already restrict them.

For plain values the output is the same "value" literal as before, so the existing golden DSL files didn't need to change.

Testing

  • New parser tests for step tags and steps_defaults (URL with a port, timestamp, JSON value). These fail on main.
  • New compiler test that compiles a notebook with a URL annotation, a JSON annotation and a label, parses the generated DSL with ast and checks the values with literal_eval. This fails on main with the SyntaxError.
  • pytest kale/tests/unit_tests passes locally, and ruff check / ruff format --check are clean.
  • Also ran kale --nb on a small notebook with the tags from the issue and checked that the generated file parses and has the right values.

Assisted-by: Claude

Update: tojson escapes non-BMP characters such as emoji as JSON surrogate pairs, which Python then reads back as lone surrogates, so an annotation with an emoji produced a DSL that couldn't be encoded as UTF-8. The values are now rendered with a small pyrepr filter (Python repr, double-quoted where possible so ordinary values come out exactly as before). Added a test with an emoji and mixed quotes. The full kale/tests run is unchanged apart from test_kfp_server_config.py::test_load_config_read_error, which fails on the base commit too.

@SajalDevX

Copy link
Copy Markdown
Author

@ada333 please review this pr once.

@jesuino jesuino 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.

Hello @SajalDevX - the changes are looking good and I plan to run it locally to test - would you please resolve the conflicts?

Thanks!

get_annotation_or_label_from_tag split the tag on ':' and then rebuilt the value with "".join, so every colon in the value was lost (URLs, timestamps, JSON). Join with TAG_SEPARATOR instead, the same way the image tag does.

Refs kubeflow#975

Signed-off-by: Sajal Kumar Jana <kakalijana1254@gmail.com>
The template wrapped the raw value in double quotes, so an annotation like {"lr": 0.01} produced a DSL file that doesn't parse. Keys are already limited to safe characters by the validators, but values are free-form strings, so render them with tojson to get a properly escaped literal.

Refs kubeflow#975

Signed-off-by: Sajal Kumar Jana <kakalijana1254@gmail.com>
Covers step tags and steps_defaults with a URL, a timestamp and a JSON value.

Refs kubeflow#975

Signed-off-by: Sajal Kumar Jana <kakalijana1254@gmail.com>
Compiles a notebook with a URL annotation, a JSON annotation and a label, then parses the generated file and reads the values back with literal_eval.

Refs kubeflow#975

Signed-off-by: Sajal Kumar Jana <kakalijana1254@gmail.com>
Refs kubeflow#975

Signed-off-by: Sajal Kumar Jana <kakalijana1254@gmail.com>
Refs kubeflow#975

Signed-off-by: Sajal Kumar Jana <kakalijana1254@gmail.com>
Refs kubeflow#975

Signed-off-by: Sajal Kumar Jana <kakalijana1254@gmail.com>
@SajalDevX

Copy link
Copy Markdown
Author

Thanks for taking a look. I rebased onto the latest main and resolved the conflict in test_compiler.py, so it should be ready to try locally.

@SajalDevX
SajalDevX force-pushed the fix/annotation-values-with-colons-and-quotes branch from cf5c3d3 to f2df1e4 Compare November 2, 2026 03:47
@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from jesuino. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@SajalDevX

Copy link
Copy Markdown
Author

@jesuino gentle ping, this is rebased on main and ready for another look.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[backend] Annotation values lose ":" and break the generated DSL when they contain quotes

2 participants