"Instance as master" through Core API?

Thanks! I think I’m close, but it’s not quite working for me, yet … whether I run those lines together or independently (commenting out one or the other), I get this same error:

objc.error: NSInternalInconsistencyException - decodeObjectForKey: class "MGOrderedDictionary" not loaded

If it helps, heres the full function that these exist in:

def copyFromInterpolatedFont(instanceIndex):
    instanceFont = font.generateInstance_error_(font.instances()[instanceIndex], None)
    instanceFontMasterID = instanceFont.fontMasters()[0].id()
    font.addFontMaster_(instanceFont.fontMasters()[0])
    newMasterID = instanceFontMasterID # these are the same; copying for clarity below

    print("\n=================================")
    print("Instance Weight: " + str(font.instances()[instanceIndex].interpolationWeight()))

    # copy glyphs from instance font to new master
    for index,glyph in enumerate(font.glyphs()): # (you can use font.glyphs()[:10] to do the first 10 glyphs only while making/testing script)
        print(". ", end="", flush=True) # shows progress while running script
        instanceGlyph = instanceFont.glyphs()[index] # make variable for glyph of interpolated font
        instanceFontLayer = instanceGlyph.layerForKey_(instanceFontMasterID) # get layer of glyph in instance font
        glyph.setLayer_forKey_(instanceFontLayer, newMasterID) # set layer in new master

    # bring kerning in from interpolated font
    font.kerning()[newMasterID] = instanceFont.kerning()[newMasterID]
    font.kerning().setObject_forKey_(instanceFont.kerning().objectForKey_(newMasterID), newMasterID)