Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using DMN Runner with Included Model fails to run #403

Closed
timwuthenow opened this issue Aug 6, 2023 · 11 comments · Fixed by apache/incubator-kie-tools#2131
Closed

Using DMN Runner with Included Model fails to run #403

timwuthenow opened this issue Aug 6, 2023 · 11 comments · Fixed by apache/incubator-kie-tools#2131
Assignees
Labels
area:dmn Related to DMN area:tools Issues affecting Apache KIE tooling projects type:bug Something is behaving unexpectedly

Comments

@timwuthenow
Copy link

When using an included model with the DMN runner within Sandbox, you cannot use a DMN that incorporates an included model in the DMN model you're currently on.

Test Scenario within Sandbox

  1. Create DMN that is to be used just as a model to be shared across multiple DMN files (dmn1.dmn)
  2. Create the DMN that a decision (dmn2) will be created from and include dmn1.dmn as an included model
  3. Go to Sandbox/Canvas and try to run a decision that uses the included model and it will fail saying it cannot find the model.

Error returned in JavaScript console:

Uncaught (in promise) Error: File '/fs_v1__ee23443a-fba5-493d-a252-60878b077e79/dmn1.dmn' doesn't exist
    at e.callback (index.js:8:2210641)
    at e.receive (index.js:8:2212425)
    at Object.receive (index.js:8:2207714)
    at ready.e.workspacesWorker.port.onmessage (index.js:8:4615565)

In best practices of models, this is a common pattern to use shared models amongst multiple decisions.

@ljmotta ljmotta self-assigned this Aug 7, 2023
@ljmotta ljmotta transferred this issue from apache/incubator-kie-tools Aug 7, 2023
@ljmotta ljmotta added type:bug Something is behaving unexpectedly area:dmn Related to DMN area:tools Issues affecting Apache KIE tooling projects and removed area:tools Issues affecting Apache KIE tooling projects labels Aug 7, 2023
@gitgabrio
Copy link

gitgabrio commented Mar 19, 2024

Looking at jitexecutor console, I found out that the editor correctly send a MultipleResourcesPayload, but it contains only the importing model, and not the imported one.
See here for example.

Please also consider the new DMN 1.5. feature of "unnamed" (i.e. default namespace) import, as tested here

@eduardocerqueira eduardocerqueira added the area:tools Issues affecting Apache KIE tooling projects label Mar 20, 2024
@tiagobento
Copy link

I couldn't reproduce this for named imports. For unnamed imports, though, I had the results not showing the external Decision, and D3 being evaluated to (null).

Please import this gist (https://gist.github.com/tiagobento/aff4c6055219b614119f6632cb6e3fbb) using the Import From URL card at https://sandbox.kie.org/dev to see what I mean.

@gitgabrio
Copy link

gitgabrio commented Mar 21, 2024

Hi @tiagobento
I see the gists.
Those models are invalid (the dmn:import is in wrong place) so they can't possibly work with jitexecutor.
I think there are also other issues with them, but I think it is not worth to spend time on them.

Beside that, please use those other models ->

https://github.com/apache/incubator-kie-drools/blob/4004fe9bf745c5eae18223cd1d3a42d8efd4566e/kie-dmn/kie-dmn-test-resources/src/test/resources/Imported_Model_Unamed.dmn
https://github.com/apache/incubator-kie-drools/blob/4004fe9bf745c5eae18223cd1d3a42d8efd4566e/kie-dmn/kie-dmn-test-resources/src/test/resources/Importing_EmptyNamed_Model.dmn
https://github.com/apache/incubator-kie-drools/blob/4004fe9bf745c5eae18223cd1d3a42d8efd4566e/kie-dmn/kie-dmn-test-resources/src/test/resources/Importing_Named_Model.dmn

I've uploaded them to sandbox, and when I open Importing_Named_Model , this is what I see in logs for validation:

[1:11](https://ibm-cloud.slack.com/archives/D04AL7XQ684/p1711023061614179)
MultipleResourcesPayload{mainURI='Importing_Named_Model.dmn', resources=[ResourceWithURI{URI='Importing_Named_Model.dmn', content='<?xml version="1.0" encoding="UTF-8"?>
<dmn:definitions xmlns="http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc"
                   xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/"
                    xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/"
                      xmlns:dmndi="http://www.omg.org/spec/DMN/20180521/DMNDI/"
                       xmlns:feel="http://www.omg.org/spec/DMN/20180521/FEEL/"
                       xmlns:dmn="http://www.omg.org/spec/DMN/20180521/MODEL/"
                       xmlns:tc="http://www.omg.org/spec/DMN/20160719/testcase"
                       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       exporter="DMN Modeler"
                       exporterVersion="6.0.3.201802231629"
                       id="_f79aa7a4-f9a3-410a-ac95-bea496edabgc"
                       name="Importing named Model"
                       namespace="http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc">
    <dmn:extensionElements>
   </dmn:extensionElements>
    <dmn:import xmlns:drools="http://www.drools.org/kie/dmn/1.1"
                     xmlns:triso="http://www.trisotech.com/2015/triso/modeling"
                     importType="http://www.omg.org/spec/DMN1-2Alpha/20160929/MODEL"
                     namespace="http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44"
                     name="Imported Model"
                     drools:modelName="Imported Model"
                     triso:fileId="eyJmIjp7InNrdSI6IjEwMmM0MDQ3LTg5NjctNGI3ZS1hODgxLTBhY2ZkNWJjOTAwMiIsIm5hbWUiOiJJbXBvcnRlZCBNb2RlbCJ9fQ=="
                     triso:fileName="Edson Tirelli/Imported Model"/>
    <dmn:inputData id="_51190b90-924d-479b-872b-4c6f3486c2cb" name="A Person">
       <dmn:variable id="_44a44de4-c0ab-408e-9ba9-983d8ec2f6b5"
                          name="A Person"
                          typeRef="Imported Model.tPerson"/>
    </dmn:inputData>
    <dmn:decision id="_bf4a9628-15ae-4887-97f2-7099426cb60f" name="Local Greeting">
       <dmn:variable id="_ecc6e0bb-a0af-4e99-aac6-5b8bed09c538"
                          name="Local Greeting"
                          typeRef="string"/>
       <dmn:informationRequirement>
          <dmn:requiredInput href="#_51190b90-924d-479b-872b-4c6f3486c2cb"/>
       </dmn:informationRequirement>
      <dmn:knowledgeRequirement>
        <dmn:requiredKnowledge href="#_42543811-b499-4608-b784-6c6f294b1c59"/>
      </dmn:knowledgeRequirement>
       <dmn:literalExpression xmlns:triso="http://www.trisotech.com/2015/triso/modeling"
                                   id="_d7e6836b-8491-487a-a653-5735daa85be1"
                                   triso:unparsed="true">
          <dmn:text>Local Hello( A Person )</dmn:text>
       </dmn:literalExpression>
    </dmn:decision>

   <dmn:decision id="_bf4a9628-15ae-4887-97f2-7099426cb60g" name="Imported Greeting">
     <dmn:variable id="_ecc6e0bb-a0af-4e99-aac6-5b8bed09c539"
                        name="Imported Greeting"
                        typeRef="string"/>
     <dmn:informationRequirement>
       <dmn:requiredInput href="#_51190b90-924d-479b-872b-4c6f3486c2cb"/>
     </dmn:informationRequirement>
     <dmn:knowledgeRequirement>
       <dmn:requiredKnowledge href="http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44#_32543811-b499-4608-b784-6c6f294b1c58"/>
     </dmn:knowledgeRequirement>
     <dmn:literalExpression xmlns:triso="http://www.trisotech.com/2015/triso/modeling"
                                 id="_d7e6836b-8491-487a-a653-5735daa85be2"
                                 triso:unparsed="true">
       <dmn:text>Imported Model.Say Hello( A Person )</dmn:text>
     </dmn:literalExpression>
   </dmn:decision>

   <dmn:businessKnowledgeModel id="_42543811-b499-4608-b784-6c6f294b1c59" name="Local Hello">
     <dmn:variable id="_a8eb10e1-30e6-40d8-a564-a868f4e0af45"
                        name="Local Hello"
                        typeRef="string"/>
     <dmn:encapsulatedLogic kind="FEEL" id="_acbb96c9-34a3-4628-8179-dfc5f583e695">
       <dmn:formalParameter id="_4a626f74-2ecc-4759-b76a-04baec6b795d"
                                 name="Person"
                                 typeRef="Imported Model.tPerson"/>
       <dmn:literalExpression id="_c173a894-3719-4d2f-a365-25850e217310">
         <dmn:text>"Local Hello " + Person.name + "!"</dmn:text>
       </dmn:literalExpression>
     </dmn:encapsulatedLogic>
   </dmn:businessKnowledgeModel>

 </dmn:definitions>
 '}]}

(there should be both models/resources, but only one is sent)
Last, I would suggest to buld jitexecutor native locally with the -Djitexecutor.dmn.log.level=DEBUG flag, to see in console what actually gets and is executed on backend side

@tiagobento
Copy link

After debugging and talking to @gitgabrio, @yesamer and @ljmotta, we found that there are three things in the files shared by @gitgabrio that are "unexpected" for KIE Sandbox, DMN Runner, and the new DMN Editor.

  1. The importType being http://www.omg.org/spec/DMN1-2Alpha/20160929/MODEL and not one of the "stable" versions.
  2. The fact that the import doesn't have a locationURI attribute. Despite its optionality, the DMN Runner needs it to work correctly. The legacy DMN Editor always populated this field, and some parts of our codebase grew around that fact. Populating locationURI at the initial normalization process is not trivial, as it requires scanning the entire Workspace for files with a matching namespace. This is a known limitation of the new DMN Editor, and will most likely be present on the new release of Apache KIE, 10.0.0.
  3. The fact that there isn't a namespace declaration for the namespace referenced by the import. This is easily doable at the initial normalization process that happen when we open a file on the new DMN Editor.

I'd say the only actionable item here in the short term would be item 3, and we can create a new task for addressing 2, as it is already listed at #796

@baldimir
Copy link

baldimir commented Apr 5, 2024

When I model a decision (from scratch using the new DMN editor), that uses an imported BKM (also modelled in the editor), imported using the empty name (1.5 feature), it also doesn't work with the runner (I am getting Unknown variable 'sayHello' errors - sayHello is the name of the imported BKM). I see the potential problem could be, how the editor adds the knowledgeRequirement:

<knowledgeRequirement id="_F4D15B4D-63AF-4956-9C39-96A1D2334146">
    <requiredKnowledge href="https://kie.org/dmn/_CDC1C967-6384-4BA9-989A-AC5385DDDFF7#_05703942-965D-4D2A-9579-E23A91DBB373" />
</knowledgeRequirement>

It is added with the namespace prefix (namespace before #). The namespace shouldn't be there, because the import with empty name imports into the default namespace of the model. This is from spec:

When the import name attribute is an empty string, the elements are imported in the default namespace of the
model. When a name collision occurs between an element in the default namespace and an imported element,
the imported element does not replace the one already in the default namespace while the elements without
name collision are imported.

So it should be used like this:

<knowledgeRequirement id="_F4D15B4D-63AF-4956-9C39-96A1D2334146">
    <requiredKnowledge href="#_05703942-965D-4D2A-9579-E23A91DBB373" />
</knowledgeRequirement>

@tiagobento @jomarko @ljmotta, should I file this as a separate issue please?

@jomarko
Copy link

jomarko commented Apr 5, 2024

@baldimir it depends, if the namespace thing you speak about and @tiagobento namespace thing he speaks about is the same or not.

to me your findings seems a little bit different scenario than #403 ticket. To me it sounds you speak about new way/alternative of importing models. To me it would make sense to have a separate ticket.

@gitgabrio
Copy link

gitgabrio commented Apr 5, 2024

I'm trying to upload a folder with the following models (with import) in the editor.
Issues:

  1. when I open the "UberModel_Importing", I see a popup:
    immagine
    but it is not clear how to save (you have to know that you must change something in the diagram)
  2. after layout, input data and other elements are duplicated
    immagine
  3. there are two validation errors detected by jitexecutor, but those models are valid (verified with engine code) so something should happen during 1.5 conversion
    immagine
  4. when I try to execute the model, another error appear (I verified: the imported model exists):
    immagine
  5. for reference, this is how the same model, without imports, should appear and work:
    immagine
    immagine

In the modified version, this is the import tag (actually missing the name attribute

<dmn:import id="_3220A0BB-1BA1-442D-A69E-7BB7CA27926A" namespace="https://www.drools.org/kie-dmn/UberModel" importType="http://www.omg.org/spec/DMN1-2Alpha/20160929/MODEL"/>

For the duplicated elements, there are two DMNSHAPE tags (the latter is the unbound one)

<dmndi:DMNShape id="dmnshape-drg-i_Flight_List" dmnElementRef="i_Flight_List" isCollapsed="false">
       <dmndi:DMNStyle>
         <dmndi:FillColor red="255" green="255" blue="255"/>
         <dmndi:StrokeColor red="0" green="0" blue="0"/>
         <dmndi:FontColor red="0" green="0" blue="0"/>
       </dmndi:DMNStyle>
       <dc:Bounds x="400" y="400" width="100" height="50"/>
       <dmndi:DMNLabel/>
     </dmndi:DMNShape> 
...
<dmndi:DMNShape id="dmnshape-drg-2-i_Flight_List" dmnElementRef="i_Flight_List" isCollapsed="false">
       <dmndi:DMNStyle>
         <dmndi:FillColor red="255" green="255" blue="255"/>
         <dmndi:StrokeColor red="0" green="0" blue="0"/>
         <dmndi:FontColor red="0" green="0" blue="0"/>
       </dmndi:DMNStyle>
       <dc:Bounds x="225" y="50" width="100" height="50"/>
       <dmndi:DMNLabel/>
     </dmndi:DMNShape>

UberModel.zip

@baldimir
Copy link

baldimir commented Apr 5, 2024

Ok, @jomarko thanks for feedback. I created it as a separate issue here #1066 @tiagobento @ljmotta

@tiagobento
Copy link

@tiagobento
Copy link

So I guess we can set this task as simply normalizing the DMN model to always have a xmlns declaration for all imports it declares. cc @ljmotta

@tiagobento
Copy link

This can land after #785 where we introduce the normalization mechanism for the DMN Editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:dmn Related to DMN area:tools Issues affecting Apache KIE tooling projects type:bug Something is behaving unexpectedly
Projects
Archived in project
7 participants