Foreach_set and foreach_get for mesh attributes in EDIT mode

Is there some way to change mesh attributes in EDIT with foreach_set and foreach_get (the same way it works in OBJECT mode) besides going to bmesh? I’ve tried and it gives me an error -RuntimeError: internal error setting the array.
What I’ve also noticed in EDIT mode all attributes length becomes 0 for some reason and I guess this is what causes an error.

Easy way to reproduce - create default blender scene, select cube and run:

from mathutils import Vector
from itertools import chain

me =
if 'test' not in me.color_attributes:'test', type='FLOAT_COLOR', domain='POINT')

attr = me.color_attributes['test']
out = [None] * 4 * 8'color', out)

new_values = [Vector((1.0, 0.0, 0.0, 0.0)) for i in range(8)]
new_values = list(chain(*new_values))'color', new_values)'color', out)

Attributes are stored differently when an object is in edit mode, so they can’t be accessed this way unfortunately. There’s some more information here: BMesh Module (bmesh) — Blender Python API

To expand on what Hans said: in edit-mode the mesh is a bmesh, so you need the bmesh functions to do anything with it.

That said, I’ll bet there’s a way to convert the edit mesh to a mesh, do some operations, and then convert it back to the edit mesh.

Curious if there actually is.

I’d guess the from_mesh and to_mesh functions mentioned here would work fine: BMesh Module (bmesh) — Blender Python API