Context has no attribute object in ZsObjectPanelUtils

Pluglug

When saving a file that uses library overrides, the following error appears in the console. It does not affect functionality but clutters the logs.

Traceback (most recent call last):
  File ".../ZenSets/sets/objects/object_panel_list.py", line 51, in get_zen_object_index
    p_act_obj = context.object
                ^^^^^^^^^^^^^^
AttributeError: 'Context' object has no attribute 'object'

Environment:

  • Windows 10
  • Blender 4.3.2
  • ZenSets 2.4.4.0

Steps to Reproduce

  1. Create two .blend files:
    • “Perfect_Character_Final_Fix_5_Latest.blend”
      • Create a collection named “Character_LINKME”.
      • Add some objects to the collection.
    • “Shot20_Using_LibraryData.blend” (working file)
      1. Go to Top Bar > File > Link.
      2. Select “Perfect_Character_Final_Fix_5_Latest.blend”.
      3. Navigate to Collections > Character_LINKME and link it.
      4. In the Outliner, select the linked collection.
      5. Go to Library Override > Make > Selected and execute.
      6. Check the console for the error.
      7. Saving the file produces the same error.

Simple Fix: Add a Fallback

class ZsObjectPanelUtils:
    def get_zen_object_index(self):
        context = bpy.context

        # Use only 'object' but not 'active_object' !!!
        p_act_obj = getattr(context, "object", None)
        if p_act_obj is None:
            Log.error("AttributeError: 'Context' object has no attribute 'object'")
            Log.info(f"context.mode: {getattr(context, 'mode', 'UNKNOWN')}")
            Log.info(f"context.screen: {getattr(context, 'screen', 'UNKNOWN')}")
            Log.info(f"context.area: {getattr(context, 'area', 'UNKNOWN')}")
            Log.info(f"context.region: {getattr(context, 'region', 'UNKNOWN')}")
            Log.info(f"context.scene: {getattr(context, 'scene', 'UNKNOWN')}")
            Log.info(f"context.view_layer: {getattr(context, 'view_layer', 'UNKNOWN')}")
            Log.info(f"context.window: {getattr(context, 'window', 'UNKNOWN')}")
            Log.info(f"context.window_manager: {getattr(context, 'window_manager', 'UNKNOWN')}")
            Log.info(f"context.active_object: {getattr(context, 'active_object', 'UNKNOWN')}")
            return -1

Zen Sets is an amazing addon! Thank you for your hard work!
Imported from Discord

AlexZhornyak

Thank you for a report, I’ll check it tomorrow morning
Imported from Discord

AlexZhornyak

<@593731426722250753>, I can confirm the bug and thank you for a solution. In all my previous tests there were no cases when context didn’t have ‘object’ attribute, so now I will apply a fallback
Imported from Discord