fix: Use raw string values instead of repr() for str types in display_string#383
fix: Use raw string values instead of repr() for str types in display_string#383
Conversation
There was a problem hiding this comment.
Pull request overview
Adjusts AppMap parameter/return-value rendering so str values are recorded as their raw string content (not repr()-quoted), improving consistency with log output and enabling reliable secret-in-log substring matching.
Changes:
- Update
display_stringto return rawstrvalues instead ofrepr(val)for strings. - Update unit tests to assert raw string values for parameters/return values.
- Update JSON “expected” AppMap fixtures to match the new string formatting.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
_appmap/event.py |
Changes display_string to emit raw str values instead of repr() output. |
_appmap/test/web_framework.py |
Updates web framework capture assertions to expect raw string values. |
_appmap/test/test_params.py |
Updates parameter-capture assertions/parameterized expectations for str values. |
_appmap/test/test_http.py |
Updates HTTP client capture assertions for raw string query param values. |
_appmap/test/test_events.py |
Updates labeled params/return value assertions and comment to reflect raw strings. |
_appmap/test/data/unittest/expected/unittest.appmap.json |
Updates expected recorded parameter/return str values (and formatting) to raw strings. |
_appmap/test/data/unittest/expected/unittest-no-test-cases.appmap.json |
Updates expected recorded str values to raw strings. |
_appmap/test/data/unittest/expected/pytest.appmap.json |
Updates expected recorded str values to raw strings. |
_appmap/test/data/pytest/expected/pytest-numpy2.appmap.json |
Updates expected recorded str return values to raw strings. |
_appmap/test/data/pytest/expected/pytest-numpy2-no-test-cases.appmap.json |
Updates expected recorded str return values to raw strings. |
_appmap/test/data/pytest/expected/pytest-numpy1.appmap.json |
Updates expected recorded str return values to raw strings. |
_appmap/test/data/pytest/expected/pytest-numpy1-no-test-cases.appmap.json |
Updates expected recorded str return values to raw strings. |
_appmap/test/data/expected.appmap.json |
Updates expected recorded str parameter/return values (including newline escaping) to raw strings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
_appmap/event.py
Outdated
| if _should_display(has_labels): | ||
| try: | ||
| value = repr(val) | ||
| value = val if isinstance(val, str) else repr(val) |
There was a problem hiding this comment.
The comment above still states that parameter display uses repr() to compute a string value, but the implementation now returns the raw value for str types. Please update the comment to reflect the new behavior so it doesn't mislead future readers.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Updated the comment in commit 622ec72 to clarify that str types are returned as-is and other types use repr().
There was a problem hiding this comment.
Looks good to me. We went back and forth on whether strings should be represented in maps verbatim or as a representation; the scanner usage does finally provide a good argument on one over the other.
The test is also a good addition.
Before merging, please:
- fixup the
issubclassand comment fix into the main feature commit, - amend the main feature commit message to include
BREAKING CHANGE:note; this changes the format of the stringified parameters.
One thing I wonder: since we're special casing strings, does it make sense to always capture them, regardless of appmap_display_params value? If it's a string, there is should be no risk of extra serialization overhead. Two potential pitfalls: 1) making sure the class is also always captured in this case, 2) do we want to truncate to avoid putting huge strings in the appmap?
a32893d to
b324b48
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ay_string BREAKING CHANGE: String values in appmap events are now recorded verbatim (e.g. "hello") rather than as Python repr (e.g. "'hello'"). This affects parameters, return values, and HTTP message fields of type builtins.str. The class field already identifies the type, so repr-quoting was redundant. Using raw string values also enables proper secret leak detection, since recorded values now match what appears in log messages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
eb77b1c to
5ee53e7
Compare
|
Hey @kgilpin, can you take a final look and rebase merge if it looks right? Re unconditional capture, I think it's a good idea (do you agree?) but best left to a separate PR. |
isinstance(val, str)withissubclass(type(val), str)to avoid__class__lookups on proxy/lazy objectsdisplay_stringdocstring/comment to reflect thatstrtypes return raw values (notrepr())