Rigify (ui.py) console error, expected str not float. #105216

Open
opened 2024-03-05 09:41:35 +01:00 by Pratik Borhade · 5 comments
Member

System Information
Operating system: Mac OS
Graphics card: M1 Max Pro

Blender Version
Broken: 4.1 beta, 4.0.2, 4.0.0
Worked: has always been broken, I just got tired of fixing it locally in my files.

TypeError: can only concatenate str (not "float") to str
Traceback (most recent call last):
  File "/Applications/Blender410.app/Contents/Resources/4.1/scripts/addons/rigify/ui.py", line 958, in poll
    has_arm = hasattr(bpy.types, 'POSE_OT_rigify_arm_ik2fk_' + rig_id)
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~

Exact steps for others to reproduce the error
Create a rig that is not rigify with rigify active.
I use autorig pro a lot of the times.
When manipulating the rig, playing, trying to add keys I get the above message spammed in the console.

Original code:

    @classmethod
    def poll(cls, context):
        obj = context.active_object
        if obj and obj.type == 'ARMATURE':
            rig_id = obj.data.get("rig_id")
            if rig_id is not None:
                has_arm = hasattr(bpy.types, 'POSE_OT_rigify_arm_ik2fk_' + rig_id)
                has_leg = hasattr(bpy.types, 'POSE_OT_rigify_leg_ik2fk_' + rig_id)
                return has_arm or has_leg

        return False

Proposed fix

@classmethod
def poll(cls, context):
    obj = context.active_object
    if obj and obj.type == 'ARMATURE':
        rig_id = obj.data.get("rig_id")
        if rig_id is not None:
            rig_id_str = str(rig_id) # Ensure rig_id is a string before concatenation converting to string
            has_arm = hasattr(bpy.types, 'POSE_OT_rigify_arm_ik2fk_' + rig_id_str)
            has_leg = hasattr(bpy.types, 'POSE_OT_rigify_leg_ik2fk_' + rig_id_str)
            return has_arm or has_leg

    return False

Original report at: blender/blender#119076

**System Information** Operating system: Mac OS Graphics card: M1 Max Pro **Blender Version** Broken: 4.1 beta, 4.0.2, 4.0.0 Worked: has always been broken, I just got tired of fixing it locally in my files. ``` TypeError: can only concatenate str (not "float") to str Traceback (most recent call last): File "/Applications/Blender410.app/Contents/Resources/4.1/scripts/addons/rigify/ui.py", line 958, in poll has_arm = hasattr(bpy.types, 'POSE_OT_rigify_arm_ik2fk_' + rig_id) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~ ``` **Exact steps for others to reproduce the error** Create a rig that is not rigify with rigify active. I use autorig pro a lot of the times. When manipulating the rig, playing, trying to add keys I get the above message spammed in the console. ## Original code: ``` @classmethod def poll(cls, context): obj = context.active_object if obj and obj.type == 'ARMATURE': rig_id = obj.data.get("rig_id") if rig_id is not None: has_arm = hasattr(bpy.types, 'POSE_OT_rigify_arm_ik2fk_' + rig_id) has_leg = hasattr(bpy.types, 'POSE_OT_rigify_leg_ik2fk_' + rig_id) return has_arm or has_leg return False ``` ## Proposed fix ``` @classmethod def poll(cls, context): obj = context.active_object if obj and obj.type == 'ARMATURE': rig_id = obj.data.get("rig_id") if rig_id is not None: rig_id_str = str(rig_id) # Ensure rig_id is a string before concatenation converting to string has_arm = hasattr(bpy.types, 'POSE_OT_rigify_arm_ik2fk_' + rig_id_str) has_leg = hasattr(bpy.types, 'POSE_OT_rigify_leg_ik2fk_' + rig_id_str) return has_arm or has_leg return False ``` Original report at: https://projects.blender.org/blender/blender/issues/119076
Pratik Borhade added the
Status
Needs Triage
Priority
Normal
Type
Report
labels 2024-03-05 09:41:35 +01:00
Author
Member

I'm not able to repro this locally but I see no harm in having the explicit conversion if it fixes a issue :)
cc @angavrilov

I'm not able to repro this locally but I see no harm in having the explicit conversion if it fixes a issue :) cc @angavrilov

Sorry I did not create it in the right place. First time reporting.

Yeah same here, when that part of the script runs it will always return an error because the concatenation is not valid with a float. At least on Mac for me.

Sorry I did not create it in the right place. First time reporting. Yeah same here, when that part of the script runs it will always return an error because the concatenation is not valid with a float. At least on Mac for me.
Member

i can't replicate it in 4.0 MacOS with any non rigify rig. Can't test with ARP because i don't own it. Seems to me related to ARP in this case.

@PratikPB2123 @nacioss Can you please attach a simple file (possibly not created with Auto Rig Pro) to replicate the issue?

i can't replicate it in 4.0 MacOS with any non rigify rig. Can't test with ARP because i don't own it. Seems to me related to ARP in this case. @PratikPB2123 @nacioss Can you please attach a simple file (possibly not created with Auto Rig Pro) to replicate the issue?
Ivan Cappiello added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2024-03-19 09:14:53 +01:00

Pending an example file that makes it possible for us to reproduce, I'd say this would be my preferred way to fix this:

has_arm = hasattr(bpy.types, f'POSE_OT_rigify_arm_ik2fk_{rig_id}')
has_leg = hasattr(bpy.types, f'POSE_OT_rigify_leg_ik2fk_{rig_id}')

Using + to concatenate strings is rarely necessary, and in this case I feel f-strings produce a more readable result.

To be complete, I'd reshuffle the entire function so that it reads more top-to-bottom instead of diagonally:

    @classmethod
    def poll(cls, context):
        obj = context.active_object
        if not obj or obj.type != 'ARMATURE':
            return False
        
        rig_id = obj.data.get("rig_id", "")
        if not rig_id:
            return False

        has_arm = hasattr(bpy.types, f'POSE_OT_rigify_arm_ik2fk_{rig_id}')
        has_leg = hasattr(bpy.types, f'POSE_OT_rigify_leg_ik2fk_{rig_id}')
        return has_arm or has_leg
Pending an example file that makes it possible for us to reproduce, I'd say this would be my preferred way to fix this: ```python has_arm = hasattr(bpy.types, f'POSE_OT_rigify_arm_ik2fk_{rig_id}') has_leg = hasattr(bpy.types, f'POSE_OT_rigify_leg_ik2fk_{rig_id}') ``` Using `+` to concatenate strings is rarely necessary, and in this case I feel f-strings produce a more readable result. To be complete, I'd reshuffle the entire function so that it reads more top-to-bottom instead of diagonally: ```python @classmethod def poll(cls, context): obj = context.active_object if not obj or obj.type != 'ARMATURE': return False rig_id = obj.data.get("rig_id", "") if not rig_id: return False has_arm = hasattr(bpy.types, f'POSE_OT_rigify_arm_ik2fk_{rig_id}') has_leg = hasattr(bpy.types, f'POSE_OT_rigify_leg_ik2fk_{rig_id}') return has_arm or has_leg ```

I have tried to trigger it without Autorig pro installed and tried to provide a test file for this. I have not been successful so far. I will append it if I can reproduce it without the addon installed.

I have tried to trigger it without Autorig pro installed and tried to provide a test file for this. I have not been successful so far. I will append it if I can reproduce it without the addon installed.
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#105216
No description provided.