Skip to content

fix(rule_translator): correct guard logic for None / all-None-list values#183

Open
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:fix/rule-translator-set-attr-logic
Open

fix(rule_translator): correct guard logic for None / all-None-list values#183
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:fix/rule-translator-set-attr-logic

Conversation

@SoundMatt

Copy link
Copy Markdown

In transform, after calling transform_value_common, the result is only stored if it is not empty:

if value != None and (isinstance(value, list) and not all([x == None for x in value])):

The bug: the second operand of and requires value to be a list. If value is any non-None scalar (a str, int, or an AST node), isinstance(value, list) is False, so the whole right-hand side is False, and the attribute is silently discarded. This causes every non-list field in every translated object to be dropped.

The intended guard is: skip if value is None, or if value is a list where every element is None. The correct expression:

if value is not None and (not isinstance(value, list) or not all(x is None for x in value)):

…alues

The guard before `set_attr` read:

    if value != None and (isinstance(value, list) and not all(...)):

The second operand of `and` requires `value` to be a list, so any
non-None scalar value (str, int, AST object) was silently dropped,
because a scalar is not a list — and that sub-expression was False.

The intent is: skip if value is None, *or* if value is a list whose
every element is None.  The correct condition is:

    if value is not None and (not isinstance(value, list) or not all(...)):

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
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