I temporarily fixed the problem by rearranging your script (please look at attached file). apparently "edit" material command does not work correctly (it's a bug). "Create" material is working so if you specify the correct soil properties while you creating the material you would be fine but editing it does not work. your issue is fixed for now but I need to fix this bug in the next release.
thanks for catching this issue. also I'm going to move this topic to "bug and problem" category so other users can see it.