diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index c1d75eb8f..322225c41 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -36,6 +36,7 @@ - fixed #11189: Controls variable missing in image asset in AssetProxy - fixed #11190: event tmpl_var in help but not available - fixed #11194: Event Asset Recurrence form is not i18n'ed + - fixed #11192: newByLineage tries to instantiate asset even if no assetId found 7.8.2 - Added scheduled vendor payout workflow activity. (Special thanks to Martin @ Oqapi) diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 0ecb6d70d..9db0ae1b3 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -821,6 +821,11 @@ sub newByLineage { $class = $assetLineage->{$lineage}{class}; unless ($id && $class) { ($id,$class) = $session->db->quickArray("select assetId, className from asset where lineage=?",[$lineage]); + if (!$id || !$class) { + $session->errorHandler->error("Couldn't instantiate asset from lineage: ".$lineage. ": class name or assetId missing"); + return undef; + } + return undef if !$id || !$class; $assetLineage->{$lineage}{id} = $id; $assetLineage->{$lineage}{class} = $class; $session->stow->set("assetLineage",$assetLineage); diff --git a/t/Asset/AssetLineage.t b/t/Asset/AssetLineage.t index 4ea371595..f03192212 100644 --- a/t/Asset/AssetLineage.t +++ b/t/Asset/AssetLineage.t @@ -17,7 +17,7 @@ use WebGUI::Session; use WebGUI::User; use WebGUI::Asset; -use Test::More tests => 90; # increment this value for each test you create +use Test::More tests => 92; # increment this value for each test you create use Test::Deep; # Test the methods in WebGUI::AssetLineage @@ -388,16 +388,19 @@ my $snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage' is ($snippet4->getId, $snippets[4]->getId, 'newByLineage returns correct Asset'); $snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage')); -is ($snippet4->getId, $snippets[4]->getId, 'newByLineage: cached lookup'); +is ($snippet4->getId, $snippets[4]->getId, '... cached lookup'); my $cachedLineage = $session->stow->get('assetLineage'); delete $cachedLineage->{$snippet4->get('lineage')}->{id}; my $snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage')); -is ($snippet4->getId, $snippets[4]->getId, 'newByLineage: failing id cache forces lookup'); +is ($snippet4->getId, $snippets[4]->getId, '... failing id cache forces lookup'); delete $cachedLineage->{$snippet4->get('lineage')}->{class}; my $snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage')); -is ($snippet4->getId, $snippets[4]->getId, 'newByLineage: failing class cache forces lookup'); +is ($snippet4->getId, $snippets[4]->getId, '... failing class cache forces lookup'); + +is(WebGUI::Asset->newByLineage($session, 'notALineage'), undef, '... returns undef'); +ok(!exists $session->stow->get('assetLineage')->{assetLineage}, '... no entry for the bad lineage in stow'); #################################################### #