Skip to content

Conversation

@andrewcrom
Copy link

In Blender 4.5 with a particular Geometry node group, I was running into issues in attributes.py:41

def _get_pointer(element: Any) -> str:

line 41, in _get_pointer
    return element["uuid"] if element else None
           ~~~~~~~^^^^^^^^
KeyError: 'bpy_struct[key]: key "uuid" not found'

The fix is to also check for element.get("uuid") which fixes the the issue.

Orginal:

def _get_pointer(element: Any) -> str:
    return element["uuid"] if element else None

Fix:

def _get_pointer(element: Any) -> str:
    if not element:
        return None
    try:
        return element.get("uuid")
    except AttributeError:
        try:
            return element["uuid"]
        except (KeyError, TypeError):
            return None

@j10er
Copy link
Owner

j10er commented Sep 23, 2025

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

@j10er j10er self-assigned this Sep 23, 2025
@j10er j10er requested a review from Copilot September 23, 2025 10:30
@j10er j10er removed their assignment Sep 23, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +44 to 53

try:
return element.get("uuid")
except AttributeError:
try:
return element["uuid"]
except (KeyError, TypeError):
return None


Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
return None

try:
return element.get("uuid")
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
return element.get("uuid")
return element.get("uuid", None)

Copilot uses AI. Check for mistakes.
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.

2 participants