Subdivision/decimation is not working as expected I am trying to subdivide the following mesh which is split in 3 objects and each object is structured from quads:

I tried both the following two functions:
def subdivide_objects():    
    obs = [o for o in bpy.data.objects
        if o.type == 'MESH' and (o.name == &quot;Wall&quot; or o.name == &quot;Ceiling&quot; or o.name == &quot;Floor&quot;)]
        
    for obj in obs:
        me = obj.data
        # New bmesh
        bm = bmesh.new()
        # load the mesh
        bm.from_mesh(me)            
        
        bmesh.ops.subdivide_edges(bm, edges=bm.edges, cuts=12, use_grid_fill=True)

        # Write back to the mesh
        bm.to_mesh(me)
        me.update()
        
def post_process_objects():
    bpy.ops.object.select_all(action='DESELECT') # Deselect all objects
    
    for o in (&quot;Wall&quot;, &quot;Ceiling&quot;, &quot;Floor&quot;):
       obj = bpy.context.scene.objects.get(o)
       bpy.context.view_layer.objects.active = obj
       if obj: 
           obj.select_set(True)
                  
           # Get into edit mode
           bpy.ops.object.mode_set(mode=&quot;EDIT&quot;)
            
           # Subdivide faces
           bpy.ops.mesh.subdivide(number_cuts=12)

           # Return back to object mode
           bpy.ops.object.mode_set(mode=&quot;OBJECT&quot;)
        
           bpy.ops.object.select_all(action='DESELECT') # Deselect all objects 

but for some reason both are not giving the desired result, but as you can see a faulty one:

Any idea what I am missing here (attached the .blend file)?


Update:
After applying @Lucca's solution, for some reason I am still facing the same problem on some specific parts of the plane as you can see in the following images:


It doesn't seem that I have duplicate vertices or something now thus ny idea why still the subdivide operator does not work properly.



Example for @batFINGER 's solution:
Still problematic:
It's not a problem with your code, but rather with your base objects. You have several overlapping vertices and edges in there.
Take a look at this screenshot:

See how there is no orange line indicating connected edges to the left?
If I pull the vertex point to the right, this happens:

This kind of 'malformed' model will play havoc with expected outputs.
There are quite a few vertices like that in your model. Fixing them by hand can be tedious, so it's a good idea to start with using Blender's 'Merge vertices by distance' functionality. In newer versions of Blender (I'm using 2.91, don't have a 2.8 install to check right now), this can be accessed by selecting two ore more vertices (using A to select all will do in your case), then pressing M -&gt; By Distance:

Just repeat this for each object, then run your script again:

I assume that looks like what you expected.
I've attached a .blend file with the fix I did: