Maniphest T94121

PyAPI: ID property group returns wrong type with iter()
Closed, Resolved

Assigned To
Campbell Barton (campbellbarton)
Authored By
Mateusz Kwaśniewski (theHarven)
Dec 15 2021, 7:00 PM
Tags
  • BF Blender
  • Python API
Subscribers
Campbell Barton (campbellbarton)
Germano Cavalcante (mano-wii)
Mateusz Kwaśniewski (theHarven)
Matt (Kickflipkid687)

Description

System Information
Operating system: Windows-10-10.0.19043-SP0 64 Bits
Graphics card: GeForce GTX 960/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 441.66

Blender Version
Broken: version: 3.0.0, caused by rB265d97556aa0
Worked: version: 2.93.6

Short description of error
Using iter() on a ID property group returns non-iterator type IDPropertyGroupViewKeys.
Seems the change was made in rB265d97556aa0: PyAPI: use iterators for ID property methods (keys, values & items).
This example code will now produce an error while it wasn't in previous versions:

C.active_object["test"] = { "key1": "val1", "key2" : "val2", "key3": "val3" }
for key in C.active_object["test"]:
    print(key)
TypeError: iter() returned non-iterator of type 'IDPropertyGroupViewKeys'

I think it should return IDPropertyGroupIterKeys instead to match the python 3.x dictionary behaviour. I made a simple change (not sure if that's a valid solution): in source/blender/python/generic/idprop_py_api.c in function BPy_IDGroup_iter() changed "return BPy_IDGroup_ViewKeys_CreatePyObject(self);" to "return BPy_IDGroup_IterKeys_CreatePyObject(self, false);" and that fixed it for me.

Exact steps for others to reproduce the error
Run the script mentioned above in the python console.

Revisions and Commits

rB Blender

Related Objects

Mentioned In
T96241: 3.1: Potential candidates for corrective releases
Mentioned Here
rB265d97556aa0: PyAPI: use iterators for ID property methods (keys, values & items)

Event Timeline

Mateusz Kwaśniewski (theHarven) created this task.Dec 15 2021, 7:00 PM
Mateusz Kwaśniewski (theHarven) added a project: Python API.
Mateusz Kwaśniewski (theHarven) renamed this task from PyAPI: ID property group returning wrong type with iter() to PyAPI: ID property group returns wrong type with iter().Dec 15 2021, 7:04 PM
Germano Cavalcante (mano-wii) updated the task description.Dec 23 2021, 4:13 PM
Germano Cavalcante (mano-wii) changed the task status from Needs Triage to Needs Information from Developers.Dec 23 2021, 7:26 PM
Germano Cavalcante (mano-wii) added subscribers: Campbell Barton (campbellbarton), Germano Cavalcante (mano-wii).

If rB265d97556aa0 is actually the commit it caused, the change may have been intentional. So needs feedback from developers.

Matt (Kickflipkid687) added a subscriber: Matt (Kickflipkid687).EditedMar 10 2022, 8:21 PM

I am hitting the issue on my own Addon as well, in Blender 3.1 Official Release.
Wondering now if I have to do some bigger refactor.. or how it impacts my code.

cutterVerts = []
        edgeVerts = []
        
        #Loop Object Dict/Data, from Modal,to get CV/EV Order to Proceed.
        for cv in context.object['TTEdgeCutterCV']:
            if(self.debug_mode):
                print(cv)
            cutterVerts += [int(cv)]

        for ev in context.object['TTEdgeCutterEV']:
            if(self.debug_mode):
                print(ev)
            edgeVerts += [int(ev)]

Python: Traceback (most recent call last):

for cv in context.object['TTEdgeCutterCV']:

TypeError: iter() returned non-iterator of type 'IDPropertyGroupViewKeys'

Campbell Barton (campbellbarton) claimed this task.Mar 10 2022, 10:48 PM
Campbell Barton (campbellbarton) closed this task as Resolved by committing rB27fb63381e9b: Fix T94121: PyAPI: ID property group returns wrong type with iter().Mar 11 2022, 12:27 AM
Campbell Barton (campbellbarton) added a commit: rB27fb63381e9b: Fix T94121: PyAPI: ID property group returns wrong type with iter().
Campbell Barton (campbellbarton) mentioned this in T96241: 3.1: Potential candidates for corrective releases.Mar 11 2022, 12:28 AM
Philipp Oeser (lichtwerk) added a commit: rB2b8d778a68b5: Fix T94121: PyAPI: ID property group returns wrong type with iter().Mar 21 2022, 2:07 PM