Conversation
When decoding the `tsg-python` output fails, we currently output an
error message such as
```
No context for node 27 in file
/templates/test_module/tests/unit/modules/test_{{module_name}}.py with
attributes {'_location': [8, 7, 8, 11], '_kind': 'Name', 'variable':
'salt'}
```
Here, the attribute dictionary contains valuable information for finding
and diagnosing the issue (in the above example, for instance, the file
contains weird template directives that make it not actually Python).
Unfortunately, the order in which the attributes are output is not
stable, which means a simple textual comparison of error messages is not
enough to establish whether two errors are the same or not.
To fix this, we now explicitly sort the attributes by key before
outputting them. This makes the error output more stable, which should
make it easier to see when it actually changes (as opposed to when it's
the same error with a different attribute ordering.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The unknown-field diagnostic still emits attributes in unstable order.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Normalizes Python TSG diagnostic attributes for stable textual comparisons.
Changes:
- Adds a sorted attribute formatter.
- Applies it to missing-context and missing-kind errors.
| File | Description |
|---|---|
python/extractor/semmle/python/parser/tsg_parser.py |
Sorts attributes in selected diagnostics. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: tausbn <1104778+tausbn@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

When decoding the
tsg-pythonoutput fails, we currently output an error message such asHere, the attribute dictionary contains valuable information for finding and diagnosing the issue (in the above example, for instance, the file contains weird template directives that make it not actually Python).
Unfortunately, the order in which the attributes are output is not stable, which means a simple textual comparison of error messages is not enough to establish whether two errors are the same or not.
To fix this, we now explicitly sort the attributes by key before outputting them. This makes the error output more stable, which should make it easier to see when it actually changes (as opposed to when it's the same error with a different attribute ordering.