diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index 0a870102b6f7a3cc1368b1a13418b8709ccd9114..a839786cce80533811c2247288564f2008b59f2e 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -770,7 +770,16 @@ static int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject
 
 static PyObject *BPy_IDGroup_iter(BPy_IDProperty *self)
 {
-  return BPy_IDGroup_ViewKeys_CreatePyObject(self);
+  PyObject *iterable = BPy_IDGroup_ViewKeys_CreatePyObject(self);
+  PyObject *ret;
+  if (iterable) {
+    ret = PyObject_GetIter(iterable);
+    Py_DECREF(iterable);
+  }
+  else {
+    ret = NULL;
+  }
+  return ret;
 }
 
 PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
diff --git a/tests/python/bl_pyapi_idprop.py b/tests/python/bl_pyapi_idprop.py
index 4cee39fafb06d45b2f153f1bbe292ff2b2125ba7..e9056137bcf77bb4017898666b909ceca612f4e8 100644
--- a/tests/python/bl_pyapi_idprop.py
+++ b/tests/python/bl_pyapi_idprop.py
@@ -172,6 +172,14 @@ class TestIdPropertyGroupView(TestHelper, unittest.TestCase):
         self.assertEqual(list(self.id.items()), [(k, v) for v, k in enumerate(text)])
         self.assertEqual(list(reversed(self.id.items())), list(reversed([(k, v) for v, k in enumerate(text)])))
 
+        # Check direct iteration is working as expected.
+        self.id["group"] = {ch: i for i, ch in enumerate(text)}
+        group = self.id["group"]
+
+        self.assertEqual(len(group), len(text))
+        self.assertEqual(list(iter(group)), text)
+
+
     def test_contains(self):
         # Check `idprop.types.IDPropertyGroupView{Keys/Values/Items}.__contains__`
         text = ["A", "B", "C"]