If the OSD has been changed (for example, if it's a new object), save it first.

Otherwise, the subsequent code may try to create an OsdMetaset object without a valid id, which will fail when trying to save it to the database.