Added a fallback case for pointers without ["uuid"]#20
Added a fallback case for pointers without ["uuid"]#20andrewcrom wants to merge 1 commit intoj10er:mainfrom
Conversation
|
Hm, this is weird, then another problem probably must have occurred when preprocessing the node trees. Before exporting, all node trees should receive a uuid if they don't yet have one |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a KeyError issue in the _get_pointer function when elements don't have a "uuid" key. The function was previously using direct dictionary access which caused exceptions in Blender 4.5 with certain Geometry node groups.
Key changes:
- Replaced direct dictionary access with try-catch fallback logic
- Added proper error handling for both
.get()method and dictionary access patterns
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| try: | ||
| return element.get("uuid") | ||
| except AttributeError: | ||
| try: | ||
| return element["uuid"] | ||
| except (KeyError, TypeError): | ||
| return None | ||
|
|
||
|
|
There was a problem hiding this comment.
The logic flow is unnecessarily complex. Consider checking if the element has dictionary-like behavior first, then use .get() with a default value. This would be more readable: return getattr(element, 'get', lambda k, default=None: element.get(k, default) if hasattr(element, 'get') else element.get(k) if k in element else default)('uuid') or simply use a more straightforward approach with hasattr checks.
| try: | |
| return element.get("uuid") | |
| except AttributeError: | |
| try: | |
| return element["uuid"] | |
| except (KeyError, TypeError): | |
| return None | |
| if hasattr(element, "get"): | |
| return element.get("uuid", None) | |
| elif isinstance(element, dict) and "uuid" in element: | |
| return element["uuid"] | |
| elif hasattr(element, "__getitem__") and "uuid" in element: | |
| try: | |
| return element["uuid"] | |
| except Exception: | |
| return None | |
| return None |
| return None | ||
|
|
||
| try: | ||
| return element.get("uuid") |
There was a problem hiding this comment.
Using element.get("uuid") without a default value returns None when the key doesn't exist, but this could mask the case where the uuid value itself is intentionally None. Consider using element.get("uuid", None) explicitly or handle the distinction between missing keys and None values.
| return element.get("uuid") | |
| return element.get("uuid", None) |
In Blender 4.5 with a particular Geometry node group, I was running into issues in attributes.py:41
The fix is to also check for element.get("uuid") which fixes the the issue.
Orginal:
Fix: