U4-9128 - IMedia.ChangeContentType causes error when saving media item

Created by Patrick Scott 30 Oct 2016, 10:26:30 Updated by Patrick Scott 03 Nov 2016, 13:10:41

I have some code which was working pre 7.5.4 (only previously used on 7.4.3). In the MediaService.Saved event if certain conditions are met, I am changing the content type of the just saved media item and then re-saving it. The error below occurs when calling ApplicationContext.Current.Services.MediaService.Save

the error is: "Cannot insert duplicate key row in object 'dbo.cmsPropertyData' with unique index 'IX_cmsPropertyData_1'. The duplicate key value is (1308, fcb1e94b-8a83-4d22-9d26-898aa672dfa0, 250). The statement has been terminated."

I have checked the new media type and it saves if I create this type directly. Also, if I remove this composition/property from the new media type it still errors with a different property.

code used is in files attached.

6 Attachments

Download MediaDragImages.vb

Download spc-page-header-image-folder.config

Download spc-page-header-image.config

Download image-composition.config

Download folder-composition.config

Download editors-notes.config

Comments

Patrick Scott 30 Oct 2016, 10:29:11

I am hoping to look at this during next week's hackathon at the UK umbraco festival


Patrick Scott 03 Nov 2016, 13:10:33

It seems to be related to compositions. The code works by copying the default media types without any compositions.

I have changed the event to Saving rather than Saved which has solved the issue for me.


Priority: Normal

Type: Bug

State: Closed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.5.4

Due in version:

Sprint:

Story Points:

Cycle: