Python "unhashable type" error assigning regexp name rule #96304

Open
opened 2022-03-10 17:02:42 +01:00 by Scott Courtney · 4 comments

System Information
Operating system: Windows-10-10.0.19044-SP0 64 Bits
Graphics card: Quadro RTX 4000/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 471.11

Blender Version
Broken: version: 3.1.0, branch: master, commit date: 2022-03-08 18:16, hash: blender/blender@c77597cd0e
Worked: Unknown (I had not previously tried this addon)

Addon Information
Name: Object Color Rules (0, 0, 2)
Author: Campbell Barton

Short description of error
Attempting to assign throws Python error in regexp match of name

Exact steps for others to reproduce the error

  • Create a simple mesh (I don't believe the details matter but will itemize below)
  • In Properties panel create a new color rule with Name as the search type
  • Optionally, change the color to distinguish from other rules (for me, this was the first rule in the project)
  • Type a search string into the match field (mine was "^REF", no quotes)
  • Click "assign to selected" with the regexp button disabled -- no error (but does not match, of course)
  • Enable the "AZ" regular expression button

Click "assign to selected" again. Error reports to console as shown below

Error traceback from system console:

location: <unknown location>:-1
Error: Python: Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\scripts\addons\object_color_rules.py", line 324, in execute
    changed_count = object_colors_calc(rules, objects)
  File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\scripts\addons\object_color_rules.py", line 167, in object_colors_calc
    if test_cb(obj, rule, cache) is not use_invert:
  File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\scripts\addons\object_color_rules.py", line 53, in NAME
    return test_name(rule, match_name, obj.name, cache)
  File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\scripts\addons\object_color_rules.py", line 36, in test_name
    cache[:] = [re_needle]`
TypeError: unhashable type: 'slice'

I do not believe the geometry is significant, but for the sake of completeness my test object was a simple cube mesh, pivot at the center of the base, pivot located at world origin, size 100x100x200 cm. Scene units (again, probably not related) are metric, centimeters, and unit scale of 0.01.

Thank you for creating this Blender addon. Please contact me if you need additional information or a file to reproduce the error. I didn't include one here because my project is large and the error can be reproduced on [essentially] a default mesh.

**System Information** Operating system: Windows-10-10.0.19044-SP0 64 Bits Graphics card: Quadro RTX 4000/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 471.11 **Blender Version** Broken: version: 3.1.0, branch: master, commit date: 2022-03-08 18:16, hash: `blender/blender@c77597cd0e` Worked: Unknown (I had not previously tried this addon) **Addon Information** Name: Object Color Rules (0, 0, 2) Author: Campbell Barton **Short description of error** Attempting to assign throws Python error in regexp match of name **Exact steps for others to reproduce the error** - Create a simple mesh (I don't believe the details matter but will itemize below) - In Properties panel create a new color rule with Name as the search type - Optionally, change the color to distinguish from other rules (for me, this was the first rule in the project) - Type a search string into the match field (mine was "^REF", no quotes) - Click "assign to selected" with the regexp button disabled -- no error (but does not match, of course) - Enable the "AZ" regular expression button # Click "assign to selected" again. Error reports to console as shown below Error traceback from system console: ``` location: <unknown location>:-1 Error: Python: Traceback (most recent call last): File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\scripts\addons\object_color_rules.py", line 324, in execute changed_count = object_colors_calc(rules, objects) File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\scripts\addons\object_color_rules.py", line 167, in object_colors_calc if test_cb(obj, rule, cache) is not use_invert: File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\scripts\addons\object_color_rules.py", line 53, in NAME return test_name(rule, match_name, obj.name, cache) File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\scripts\addons\object_color_rules.py", line 36, in test_name cache[:] = [re_needle]` TypeError: unhashable type: 'slice' ``` I do not believe the geometry is significant, but for the sake of completeness my test object was a simple cube mesh, pivot at the center of the base, pivot located at world origin, size 100x100x200 cm. Scene units (again, probably not related) are metric, centimeters, and unit scale of 0.01. Thank you for creating this Blender addon. Please contact me if you need additional information or a file to reproduce the error. I didn't include one here because my project is large and the error can be reproduced on [essentially] a default mesh.
Author

Added subscriber: @Syscrusher

Added subscriber: @Syscrusher
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Added subscribers: @PratikPB2123, @ideasman42

Added subscribers: @PratikPB2123, @ideasman42

I'm not sure if this qualifies as a fix, it's more like a workaround for anyone looking to use regex. I removed the caching code, as I don't know how else to fix it for the time being with my limited knowledge in Python, This seems to be working, I'm not sure what performance penalty this brings in, however its quite negligible to notice on my file containing 971 objects (35 geos, 12 empties, Rest are Cameras) with approx 51000000 tris. Be sure to save your file before using this on your mission critical file.

These are the changes I made, removed 1 level of indentation on lines 18 and 19, added # for rest of the lines from line 17 to 22, to comment out the code in

\scripts\addons\object_color_rules.py

#        if not cache:
        import re
        re_needle = re.compile(needle)
#            cache[:] = [re_needle]
#        else:
#            re_needle = cache[0]

If possible, I'll look into the caching code and update.

I'm not sure if this qualifies as a fix, it's more like a workaround for anyone looking to use regex. I removed the caching code, as I don't know how else to fix it for the time being with my limited knowledge in Python, This seems to be working, I'm not sure what performance penalty this brings in, however its quite negligible to notice on my file containing 971 objects (35 geos, 12 empties, Rest are Cameras) with approx 51000000 tris. Be sure to save your file before using this on your mission critical file. These are the changes I made, removed 1 level of indentation on lines 18 and 19, added # for rest of the lines from line 17 to 22, to comment out the code in \scripts\addons\object_color_rules.py ```python # if not cache: import re re_needle = re.compile(needle) # cache[:] = [re_needle] # else: # re_needle = cache[0] ``` If possible, I'll look into the caching code and update.
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 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#96304
No description provided.