return the original materials with python
You can keep the original material index in a mesh.polygon_layers_int layer. Or save the material name in a polygon_layers_string As shown in sample code below.

import bpy
context = bpy.context
scene = context.scene

obj = context.object
mesh = obj.data

save_mat_layer = mesh.polygon_layers_int.get('material_index')
if save_mat_layer is None:
    save_mat_layer = mesh.polygon_layers_int.new(name='material_index')

save_matname_layer = mesh.polygon_layers_string.get('material_name')
if save_matname_layer is not None:
    save_matname_layer = mesh.polygon_layers_string.new(name='material_name')

for f in mesh.polygons:
    save_mat_layer.data[f.index].value = f.material_index
    save_matname_layer.data[f.index].value = mesh.materials[f.material_index].name.encode()


PS: not sure if obtaining desired result for the string layer.