U4-7108 - Calling ContentTypeService.GetMediaType(id) with a guid that isn't in umbraco results in a SQL error

Created by Kevin Jump 15 Sep 2015, 13:52:32 Updated by Stephan 16 Sep 2015, 09:09:18

If you call the ContentTypeService.GetMediaType(Guid id) method with a GUID of a media type that isn't present in umbraco you get a SQL error

Stack Trace: [SqlException (0x80131904): Incorrect syntax near ')'.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +408 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +768 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4489 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +117 System.Data.SqlClient.SqlDataReader.get_MetaData() +126 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +522 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +3117 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +536 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +104 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +1113 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +1785 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +183 StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior) in c:\Code\github\SamSaffron\MiniProfiler\StackExchange.Profiling\Data\ProfiledDbCommand.cs:235 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() +17 Umbraco.Core.Persistence.d__71.MoveNext() +897 System.Collections.Generic.List1..ctor(IEnumerable1 collection) +536 System.Linq.Enumerable.ToList(IEnumerable1 source) +76 Umbraco.Core.Persistence.Repositories.ContentTypeQueryMapper.MapGroupsAndProperties(Int32[] contentTypeIds, Database db, ISqlSyntaxProvider sqlSyntax, IDictionary2& allPropertyTypeCollection, IDictionary2& allPropertyGroupCollection) +744 Umbraco.Core.Persistence.Repositories.ContentTypeQueryMapper.MapContentTypeChildren(IContentTypeComposition[] contentTypes, Database db, ISqlSyntaxProvider sqlSyntax, TRepo contentTypeRepository, IDictionary2 allParentContentTypeIds) +260 Umbraco.Core.Persistence.Repositories.MediaTypeRepository.PerformGet(Guid id) +182 Umbraco.Core.Persistence.Repositories.GuidReadOnlyContentTypeBaseRepository.PerformGet(Guid id) +41 Umbraco.Core.Persistence.Repositories.RepositoryBase2.Get(TId id) +258 Umbraco.Core.Persistence.Repositories.ContentTypeBaseRepository`1.Get(Guid id) +38 Umbraco.Core.Services.ContentTypeService.GetMediaType(Guid id) +117

this is because the presence of the MediaType is not checked before attempting to map properties in ContentTypeBaseRepository.cs

a pull request has been submitted - this issue is just to cover that PR.

Comments

Stephan 16 Sep 2015, 09:09:05

Pushed 5b1ed8bef511e04b8c5613792b62cd79ee1f7e62 - fixed - not using the PR because fixing the root cause of the issue. Thanks anyways!


Priority: Normal

Type: Bug

State: Fixed

Assignee: Stephan

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted: Pull request

Affected versions: 7.3.0

Due in version: 7.3.0

Sprint:

Story Points:

Cycle: