The problem here is that the apply modifier operator is not passing in the evaluated object in the context, as happens with regular modifier evaluation.
If we work around this in just the explode modifier it will still cause issues elsewhere, so best to fix it at the root.
I'm trying to fix this, but I have some trouble.
One question: What exactly does DEG_get_evaluated_object do in case when the object is not fully evaluated? It feels weird to pass the "already evaluated" object into the modifier that actually does the evaluation. Where am I wrong?
Right, maybe passing the fully evaluated object is not right either.
I guess technically what should happen is to re-evaluate the object up to the point of the modifier, and then apply the result from that. Because you do need object transform and animation to be evaluated on the object, in case the modifier depends on it.
@Sergey Sharybin (sergey), do you have an opinion on the right solution for this?
You are not supposed to use DEG_get_evaluated_object from within evaluation. The evaluation is to be performed on an exact objects which were passed to the evaluation.
From the quick thoughts, think the solution is to make Apply modifier to apply them on an evaluated object and then copy result back (before applying BKE_object_eval_reset() will probably be needed to be called).