util: look up the integer range by string key, not the range builtin#5384
Merged
make-all merged 1 commit intoJun 22, 2026
Merged
Conversation
representation() called dp._config.get(range) when building a sample DPS value for an integer datapoint. The dict comes from YAML, so all keys are strings; passing the built-in range() function as a key meant the lookup always returned None and the configured min was ignored, falling back to 0 for every int DP. Read the 'range' string key instead, and guard against a non-dict or missing 'min' before subscripting. This matters for the CLI utilities (duplicates, match_against) that consume make_sample_dps: a device with range.min: 40 was producing a sample of 0, which can fail _typematch against configs that require values in [40, 70] and turn a real-match case into a false negative.
Owner
|
I don't think there are any real consequences of this, as none of the current utilities or matching function check whether sample values are in range or not, and the other conditions checked for here are config errors, so it is better that the exception is thrown to alert to an invalid config. I think the quotes around range are correct, but the rest of the defensive programming changes are not adding value. |
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.
Summary
util/common_funcs.py:representation()looked up the integer range by passing the built-inrangefunction as a key. The config dict is loaded from YAML, so the actual key is the string"range"— the lookup always returnedNoneand a sample DP value of0was used regardless of the configuredmin. The CLI utilitiesduplicatesandmatch_against(which usemake_sample_dps) silently produced wrong sample values, and a real device match could be turned into a false negative if the duplicate detection was matching against arange: {min: 40, max: 70}config."range"and guards against a non-dict / missingminbefore subscripting, so the function returns the configured minimum when present and falls back to0otherwise.Verification
rangeconfig. Before the fix, both returned0. After the fix, the DP withrange.min: 5returns5and the DP without a range returns0.