fix: handle list[dict] variable values in BuildVariable hash#3072
fix: handle list[dict] variable values in BuildVariable hash#3072gaetan-h wants to merge 2 commits into
Conversation
When a config variable has a list-of-dicts value (e.g. a site_readiness list where each item is a dict of per-site fields), both load_raw() and load() wrapped it in tuple() — but the dicts inside the tuple are still unhashable. This caused compare_modules() to crash with: TypeError: unhashable type: 'dict' when calling set(current_module_variables) or set(cached_module.build_variables). Fix: extract a _to_hashable() helper that recursively converts lists and dicts to nested tuples of sorted key-value pairs, making any variable value safe to use in a set() or as a frozen dataclass hash. Applied in both load_raw() (live variables from config parsing) and load() (variables read back from build_info.*.yaml cache).
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
Module Name and Location columns were truncated with '…' when the terminal was not wide enough. Add min_width and no_wrap=True so the table expands beyond the terminal width and allows horizontal scrolling rather than hiding content. Also justify numeric columns right and wrap long header labels to reduce header row height.
Summary
cdf modules list(and any command that callscompare_modules()) crashes with:when a config variable has a list-of-dicts value — for example:
Root Cause
BuildVariableis afrozen dataclass, so Python auto-generates__hash__from all fields includingvalue. Bothload_raw()andload()converted list values withtuple(value), but if the list contains dicts, those dicts end up inside the tuple and are still unhashable — causingset()to fail.Fix
Extract a
_to_hashable()helper that recursively converts lists and dicts to nested tuples of sorted key-value pairs:Applied in both:
load_raw()— live variables parsed fromconfig.*.yamlBuildVariable.load()— variables read back frombuild_info.*.yamlcacheTests
Two new test cases in
test_build_variables.py:test_load_raw_list_of_dicts_is_hashable— verifiesload_raw()with alist[dict]variable produces a hashableBuildVariabletest_load_from_cache_list_of_dicts_is_hashable— verifiesBuildVariable.load()(cache read path) does the sameAll 10 existing + new tests pass.