Applying modifiers in a script I've seen a couple of good examples of creating modifiers and applying them to objects, but they don't seem to be working for me. Or at least are only working part way.

My function takes a modifier type (in my test case, 'UNION') and a list of objects. The first object is the target and the rest are going to be the modifications.

When this executes, my target still has the stack of modifiers attached to it. I have to manually push the Apply button in the UI for each one. How can I make that happen in my script?

def applyModifier (self, mod, items):
    target = items[0]
    for i in range(1, len(items)):
        objB = items[i]
        boo = target.modifiers.new('Booh', 'BOOLEAN')
        boo.object = objB
        boo.operation = mod
        bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Booh")
        bpy.context.scene.objects.unlink(objB)
    return target


The subordinate objects do unlink from the scene, so I know that bit of code is executing properly.
Since you're using something from bpy.ops, you need to get the editor state right (this is the failing of most of bpy.ops).

You probably need to set bpy.context.scene.objects.active = target

and in 2.8+

context.view_layer.objects.active = target