U4-2752 - ContentService.DeleteVersion and DeleteVersions fail

Created by Morten Bock 30 Aug 2013, 08:08:21 Updated by Sebastiaan Janssen 31 Aug 2013, 17:21:20

It seems that some bad sql is generated when trying to delete versions.

Code sample 1:

var contentService = UmbracoContext.Services.ContentService; var allVersions = contentService.GetVersions(1234); var oldVersion = allVersions.OrderByDescending(v => v.UpdateDate).Skip(5).FirstOrDefault(); if (oldVersion != null) { contentService.DeleteVersion(oldVersion.Id, oldVersion.Version, true); }

System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'nodeId'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior) in c:\Code\github\SamSaffron\MiniProfiler\StackExchange.Profiling\Data\ProfiledDbCommand.cs:line 235 at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() at Umbraco.Core.Persistence.Database.d__71.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Umbraco.Core.Persistence.Repositories.VersionableRepositoryBase`2.DeleteVersions(Int32 id, DateTime versionDate) at Umbraco.Core.Services.ContentService.DeleteVersions(Int32 id, DateTime versionDate, Int32 userId) at Umbraco.Core.Services.ContentService.DeleteVersion(Int32 id, Guid versionId, Boolean deletePriorVersions, Int32 userId)

Code sample 2:

var contentService = UmbracoContext.Services.ContentService; var allVersions = contentService.GetVersions(1234); var oldVersions = allVersions.OrderByDescending(v => v.UpdateDate).Skip(5); foreach (var oldVersion in oldVersions) { contentService.DeleteVersion(oldVersion.Id, oldVersion.Version, false); }

Throws this exception:

System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'newest'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior) in c:\Code\github\SamSaffron\MiniProfiler\StackExchange.Profiling\Data\ProfiledDbCommand.cs:line 235 at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() at Umbraco.Core.Persistence.Database.d__71.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source) at Umbraco.Core.Persistence.Repositories.VersionableRepositoryBase`2.DeleteVersion(Guid versionId) at Umbraco.Core.Services.ContentService.DeleteVersion(Int32 id, Guid versionId, Boolean deletePriorVersions, Int32 userId)

Comments

Sebastiaan Janssen 31 Aug 2013, 17:21:20

Fixed in revision 5640daff321958c70cf7993677d3eaab82170f39


Priority: Normal

Type: Bug

State: Fixed

Assignee: Morten Christensen

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.1.4

Due in version: 6.1.5

Sprint:

Story Points:

Cycle: