Skip to content

Fix apostrophes in dropdown names breaking generated revision files - #287

Open
JeetuSK0808 wants to merge 1 commit into
dynotx:mainfrom
JeetuSK0808:fix/escape-quotes-in-revision-files
Open

JeetuSK0808 wants to merge 1 commit into
dynotx:mainfrom
JeetuSK0808:fix/escape-quotes-in-revision-files

Conversation

@JeetuSK0808

Copy link
Copy Markdown

What was wrong

BaseOperation.__repr__ wraps string arguments in single quotes with no escaping (liminal/base/base_operation.py, line 78), and that's what revision_file_string() writes into autogenerated revision files. So a dropdown name or option with an apostrophe, like 5' UTR on a Primer End dropdown, is written as:

b.CreateDropdownOption('Primer End', '5' UTR', 0)

which isn't valid Python, and Revision.parse_from_file fails on it the next time the timeline loads. #265 fixed the same kind of thing in the generated dropdown model files, but revision files go through this separate path.

Fix

Use repr(str(v)) for string arguments (1 line). It quotes and escapes, so the line above becomes b.CreateDropdownOption('Primer End', "5' UTR", 0). For strings without a quote or backslash the output is byte for byte the same as before, so existing revision files don't change.

Tests

New liminal/tests/test_revision_file_quotes.py:

  • test_revision_file_string_round_trips_quotes: 3 operations with apostrophes and a double quote, each evaluated back from revision_file_string() and compared with the original.
  • test_revision_file_with_apostrophes_parses_back: writes a whole revision file with write_revision_file and reads it back with Revision.parse_from_file.

Results (run locally, macOS arm64, Python 3.12)

  • New tests on main without the fix: all 4 fail.
  • With the fix: pytest liminal gives 44 passed (the 40 existing plus the 4 new).
  • ruff check, ruff format --check and mypy --sqlite-cache are clean.
  • I also generated 400 random revision files with lab-style names (skewed toward apostrophes on purpose). 393 couldn't be parsed back on main, and none with the fix.

🤖 Generated with Claude Code

BaseOperation.__repr__ wrapped string arguments in single quotes with
no escaping, so a dropdown name or option like 5' UTR was written into
the revision file as '5' UTR', which isn't valid Python, and
Revision.parse_from_file failed the next time the timeline loaded.
Use repr() for string arguments instead. For strings without a quote
or backslash the output is byte for byte the same, so existing
revision files don't change.

Adds tests that round-trip operations with apostrophes and double
quotes, and a whole revision file written and parsed back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant