3
Vote

Multiple ContentItemVersionRecords published for same parent ContentItemRecord

description

I've had an issue where a content item had multiple records in the 'ContentItemVersionRecords' table marked as publish. In my case there were two marked as Published.

This was causing a crash in this function in DefaultContentManager.cs on the 'SingleOrDefault()' call.
public virtual void Publish(ContentItem contentItem) {
            if (contentItem.VersionRecord.Published) {
                return;
            }
            // create a context for the item and it's previous published record
            var previous = contentItem.Record.Versions.SingleOrDefault(x => x.Published);
            var context = new PublishContentContext(contentItem, previous);

            // invoke handlers to acquire state, or at least establish lazy loading callbacks
            Handlers.Invoke(handler => handler.Publishing(context), Logger);

            if (previous != null) {
                previous.Published = false;
            }
            contentItem.VersionRecord.Published = true;

            Handlers.Invoke(handler => handler.Published(context), Logger);
        }
Unfortunately I don't know how to reproduce this. I guess it's a kind of glitch that would be quick hard to replicate.

Perhaps caused by double-clicking a button?

comments

pszmyd wrote May 23, 2013 at 4:13 PM

The real question here is how this happened (multi-threading issue?) and how to prevent it (locking session factory?).