finos/legend-pure

SubtypeOf should fallback on graph _subTypeOf when to search for classes in the graph

aziemchawdhary-gs opened this issue · 0 comments

Bug Report

Steps to Reproduce:

  1. Use legend-pure version 1.36.1, legend-engine version 2.42.0 and current version of legend-studio.

The following model/mapping will fail when executing the mapping test:

Class test::MilestonedData
{
  FROM_Z: StrictDate[0..1];
  THRU_Z: StrictDate[0..1];
}

Class test::MarketListIdentifier extends test::MilestonedData
{
  identifier: String[1];
}

Class test::TopLevelTarget
{
  id: String[*];
}

Class test::TopLevelSource
{
  current: test::MarketListIdentifier[*];
}

function test::f(t: test::TopLevelSource[1]): test::MarketListIdentifier[*]
{
   $t.current->filter(m|$m->test::isNonEmptyDates())
}

function test::isNonEmptyDates(milestonedData: test::MilestonedData[1]): Boolean[1]
{
   $milestonedData.THRU_Z->isNotEmpty() && $milestonedData.FROM_Z->isNotEmpty()
}


###Mapping
Mapping test::M
(
  test::TopLevelTarget: Pure
  {
    ~src test::TopLevelSource
    id: $src->test::f().identifier
  }

  MappingTests
  [
    test_1
    (
      query: |test::TopLevelTarget.all()->graphFetchChecked(#{test::TopLevelTarget{id}}#)->serialize(#{test::TopLevelTarget{id}}#);
      data:
      [
        <Object, JSON, test::TopLevelSource, '{"current":[{"FROM_Z":"2021-10-11","THRU_Z":"2021-11-01","delete":true,"topLevel":{"marketList":[{"FROM_Z":"2021-10-23","THRU_Z":"2021-11-20","delete":true,"identifier":"identifier 51"}],"id":["id 54"]},"identifier":"identifier 67"}],"proposed":{"FROM_Z":"2021-11-13","THRU_Z":"2021-11-19","topLevel":{"marketList":[{"FROM_Z":"2021-11-23","THRU_Z":"2021-11-12","identifier":"identifier 59"}],"id":["id 4"]},"identifier":"identifier 68"}}'>
      ];
      assert: '{}';
    )
  ]
)

Expected Result:

Expected result is successful execution of the mapping test

Actual Result:

Test fails with error: ClassNotFoundException: org.finos.legend.pure.generated.Root_test_MilestonedData

Additional Context:

The bug is due to this line:

if($propertyPathOwner != $nodeClass && $propertyPathOwner->subTypeOf($nodeClass->toOne()),

Here, the call to subTypeOf should be replaced with _subTypeOf and is fixed here: #322
However, to avoid future issues with subTypeOf, the behaviour should be changed: in the case that the class is not found, we should fall back on searching the graph for the class (as _subTypeOf does).