Skip to content

fix: handle null turbo_controller without spurious warnings - #284

Open
jasonstjohn wants to merge 1 commit into
xopt-org:mainfrom
jasonstjohn:fix/null-turbo-controller-warning
Open

fix: handle null turbo_controller without spurious warnings#284
jasonstjohn wants to merge 1 commit into
xopt-org:mainfrom
jasonstjohn:fix/null-turbo-controller-warning

Conversation

@jasonstjohn

Copy link
Copy Markdown
## Fix explanation

When `turbo_controller: null` is explicitly set in a tuning template's generator section, Badger was producing a misleading warning:

Could not find compatible class for  in field turbo_controller


The warning appeared repeatedly (once per generator) because the code checked `defaults.get(field)` which returns `None` both when:
1. The field is missing from the config (legitimate case to warn about)
2. The field is explicitly set to `null` (expected behavior, no warning needed)

## Root cause

In `badger/gui/components/pydantic_editor.py`, the code used `defaults.get(field, {})` which:
- Returns `{}` when the key doesn't exist → triggers warning for missing field
- Returns `None` when key exists but value is `null``None` was then treated as empty dict, resulting in empty string for `name`, causing repeated warnings

## The fix

1. Changed `defaults.get(field, {})` to `defaults.get(field)` to properly detect missing fields
2. When `special_item_dict` is empty (from `null`), default the name to `"null"` instead of `""`

This way:
- Missing field → warning displayed (correct)
- `turbo_controller: null` → no warning, "null" selected (correct)

### Diff

```diff
--- a/badger/gui/components/pydantic_editor.py
+++ b/badger/gui/components/pydantic_editor.py
@@ -754,15 +754,23 @@ class PydanticEditor(QWidget):
             field: str = "turbo_controller"
             # Get value without default - if key doesn't exist, get() returns None
             # If key exists but value is None (from null in YAML), it's also None
             # We need to distinguish these cases for the warning
             special_item_dict: dict[str, Any] | None = defaults.get(field)
 
             if special_item_dict is None:
-                logger.warning(
+                # Check if key exists in dict - if not, warn; if yes, it's explicitly null
+                if field not in defaults:
+                    logger.warning(
                         f"Generator has {field} set but no compatible {field} exists in defaults. "
                         "Item has likely been filtered out from not being included in defaults."
                     )
+                special_item_dict = {}
-
+ 
             special_item_dict["vocs"] = self.vocs.model_dump()
 
-            name = special_item_dict.get("name", "")
+            # Use the name from dict, or "null" if dict is empty (null was set)
+            name = special_item_dict.get("name", "null" if not special_item_dict else "")

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