I'm not sure why yet but if I change a measure from 4/4 to 5/4 using this code, I end up with a quarter rest and a whole rest. Trying to select the measure will only select the whole rest.
Without this patch, I end up with a whole rest and a quarter (which is better?), and selecting the measure works ok.