From 30796388b0b37ffe97b8d2456d309723c5bfc6d7 Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Tue, 17 Apr 2018 22:06:14 +0200 Subject: [PATCH] Fixed: Radarr not loading with an invalid sort key. --- src/NzbDrone.Core/Datastore/BasicRepository.cs | 2 +- .../Datastore/Extensions/PagingSpecExtensions.cs | 16 ++++++++++++++-- src/NzbDrone.Core/Movies/MovieRepository.cs | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core/Datastore/BasicRepository.cs b/src/NzbDrone.Core/Datastore/BasicRepository.cs index cdc452284..2a073556a 100644 --- a/src/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/src/NzbDrone.Core/Datastore/BasicRepository.cs @@ -259,7 +259,7 @@ namespace NzbDrone.Core.Datastore protected virtual SortBuilder GetPagedQuery(QueryBuilder query, PagingSpec pagingSpec) { return query.Where(pagingSpec.FilterExpression) - .OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()); + .OrderBy(pagingSpec.OrderByClause(x => x.Id), pagingSpec.ToSortDirection()); } protected void ModelCreated(TModel model) diff --git a/src/NzbDrone.Core/Datastore/Extensions/PagingSpecExtensions.cs b/src/NzbDrone.Core/Datastore/Extensions/PagingSpecExtensions.cs index 39cc5b7a6..5c0f072ce 100644 --- a/src/NzbDrone.Core/Datastore/Extensions/PagingSpecExtensions.cs +++ b/src/NzbDrone.Core/Datastore/Extensions/PagingSpecExtensions.cs @@ -6,9 +6,21 @@ namespace NzbDrone.Core.Datastore.Extensions { public static class PagingSpecExtensions { - public static Expression> OrderByClause(this PagingSpec pagingSpec) + public static Expression> OrderByClause(this PagingSpec pagingSpec, Expression> defaultExpression = null) { - return CreateExpression(pagingSpec.SortKey); + try + { + return CreateExpression(pagingSpec.SortKey); + } + catch + { + if (defaultExpression == null) + { + return x => x; + } + return defaultExpression; + } + } public static int PagingOffset(this PagingSpec pagingSpec) diff --git a/src/NzbDrone.Core/Movies/MovieRepository.cs b/src/NzbDrone.Core/Movies/MovieRepository.cs index 90502e39d..a64b008cf 100644 --- a/src/NzbDrone.Core/Movies/MovieRepository.cs +++ b/src/NzbDrone.Core/Movies/MovieRepository.cs @@ -161,7 +161,7 @@ namespace NzbDrone.Core.Movies { return Query.Where(pagingSpec.FilterExpression) .AndWhere(m => m.MovieFileId == 0) - .OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()) + .OrderBy(pagingSpec.OrderByClause(x => x.SortTitle), pagingSpec.ToSortDirection()) .Skip(pagingSpec.PagingOffset()) .Take(pagingSpec.PageSize); } @@ -179,7 +179,7 @@ namespace NzbDrone.Core.Movies return Query.Where(pagingSpec.FilterExpression) .AndWhere(m => m.MovieFileId != 0) .AndWhere(BuildQualityCutoffWhereClause(qualitiesBelowCutoff)) - .OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()) + .OrderBy(pagingSpec.OrderByClause(x => x.SortTitle), pagingSpec.ToSortDirection()) .Skip(pagingSpec.PagingOffset()) .Take(pagingSpec.PageSize); }