Skip to content

Commit

Permalink
Fixed: Edge case where import fails due to DB relationship mismatch
Browse files Browse the repository at this point in the history
Closes #3243
  • Loading branch information
markus101 committed Aug 5, 2019
1 parent bd9bded commit 27f4356
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Expand Up @@ -3,6 +3,7 @@
using FluentAssertions;
using Marr.Data;
using NUnit.Framework;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
using NzbDrone.Core.Parser.Model;
Expand Down Expand Up @@ -92,5 +93,18 @@ public void should_be_reject_if_file_size_is_the_same()

Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
}

[Test]
public void should_be_accepted_if_file_cannot_be_fetched()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.TheFirst(1)
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>((EpisodeFile)null))
.Build()
.ToList();

Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
}
}
}
Expand Up @@ -30,6 +30,16 @@ public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem down
return Decision.Accept();
}

var episodeFile = episodeFiles.First().Value;

if (episodeFile == null)
{
var episode = localEpisode.Episodes.First();
_logger.Trace("Unable to get episode file details from the DB. EpisodeId: {0} EpisodeFileId: {1}", episode.Id, episode.EpisodeFileId);

return Decision.Accept();
}

if (episodeFiles.First().Value.Size == localEpisode.Size)
{
_logger.Debug("'{0}' Has the same filesize as existing file", localEpisode.Path);
Expand Down

0 comments on commit 27f4356

Please sign in to comment.