# Driver script not updating mesh

I have a driver script being called on an empty's position properties. When the user moves the empty, I'm regenerating a mesh based on the position of the empty. The driver script runs, but the mesh doesn't visibly change (until I go into edit mode afterward). Here's basically what the script is doing:

obj = bpy.data.objects.get(name)
mesh = obj.data
mesh.clear_geometry()
mesh.from_pydata(verts, [], faces)


I tried calling obj.update_tag() but that did nothing (perhaps it's too late in dependency graph update?). I also tried calling context.view_layer.update() but that gave the error "Dependency graph update requested during evaluation".

I'm using a driver script because it makes it easy to bind to specific property changes of the empty (position, scale, etc.).

Is there a better way to be doing this or a way to force the mesh to update?

2. Added a depsgraph_update_post handler script that does the actual mesh changes (see sample code above).