Json serialization/deserialization bugs

Hi All,

I identified the following models that succeed to serialize but fail when deserialzing:
1a

package MechanicalObjectExample {
    abstract item def MechanicalObject {
        attribute mass :> ISQ::mass;
    }

    abstract item mechanicalObjects[*] : MechanicalObject;
    metadata def <mec> MechanicalObjectMetadata :> Metaobjects::SemanticMetadata {
        :>> baseType = mechanicalObjects meta SysML::Usage;
    }

    part def DroneSystem {
        part def Drone {
            #mec part battery {
                attribute :>> mass = 2.5 [SI::kg];
            }
            #mec part propulsionUnit {
                attribute :>> mass = 0.5 [SI::kg];
            }            
        }
    }
}

1b)

package FlashlightStarterModel {
    package FlashlightSpecificationAndDesign {
        package Parts {
        }
    }
    package Views1{
        //private import Views::*;
        view flashlightPartsTree{
            expose FlashlightSpecificationAndDesign::Parts::**;
            filter @SysML::PartUsage;
            render Views::asTreeDiagram;
        }
    }
}

both give: TypeError: cannot unpack non-iterable NoneType object

package FlashlightStarterModel {
            part flashlight {
                exhibit state flashlightStates {
                    state off;
                    state on {
                    }
                    transition start then off;
                }
        }
}

This just runs indefinitely because of the transition statement. If I comment that line it serializes and deserializes just fine.

Thanks,

Robert

Thanks for the reports. These have already been fixed for the next release.

Fixed in v0.8.2

Hi @Daumantas , Thank you, I tested it.

1a and 1b are fixed in 0.8.2 but 2 still crashes (literally. it goes into dome infinite loop) because of the

line: transition start then off;

Maybe that line should throw a validation error. It looks like it gets into trouble because ‘start’ is a keyword
in activities.

I tried initial transition in state machine:
transition first start then off;

Every statemachine as a start state by default, so that should work.

but that crashes automator too;

entry; then off;
works

Can you provide a script that triggers the bug?

The following runs fine and prints nothing with any combination of serialization options (except include_implied=True always to ensure order of implicit relationships)

import difflib
import syside

SRC = """\
package FlashlightStarterModel {
            part flashlight {
                exhibit state flashlightStates {
                    state off;
                    state on {
                    }
                    transition start then off;
                }
        }
}
"""

model, _ = syside.load_model(sysml_source=SRC)

with model.user_docs[0].lock() as doc:
    src = syside.sexp(doc.root_node, print_references=True)

    json = syside.json.dumps(
        doc.root_node,
        options=syside.SerializationOptions.minimal().with_options(
            include_derived=True,
            include_implied=True,
            include_default=True,
            include_optional=True,
            include_redefined=True,
        ),
        include_cross_ref_uris=True,
    )

model, out = syside.json.loads([("memory:///test.sysml", json)])

dst = syside.sexp(out[0][0].document.root_node, print_references=True)

print(
    "\n".join(
        difflib.unified_diff(
            src.splitlines(),
            dst.splitlines(),
            fromfile="input.sysml",
            tofile="output.sysml",
        )
    )
)

Hi @Daumantas , it crashes in

syside.pprint(root_namespace, printer, printer_cfg)
import syside
import pathlib
import os
from pprint import pprint

EXAMPLE_DIR = pathlib.Path(os.getcwd())
MODEL_FILE_PATH = EXAMPLE_DIR / 'Test.sysml'

model, _ = syside.try_load_model([MODEL_FILE_PATH])

with model.user_docs[0].lock() as doc:
    root_node = doc.root_node

string = syside.json.dumps(
    root_node,
    syside.SerializationOptions.minimal().with_options(
        use_standard_names=True,
        include_derived=True,
        include_redefined=True,
        include_default=False,
        include_optional=False,
        include_implied=True,
    ),
)

deserialized_model, _ = syside.json.loads(string, "memory:///import.sysml")
map = syside.IdMap()

for mutex in syside.Environment.get_default().documents:
    with mutex.lock() as dep:
        map.insert_or_assign(dep)

report, success = deserialized_model.link(map)
root_namespace = deserialized_model.document.root_node
printer_cfg = syside.PrinterConfig(line_width=80, tab_width=2)
printer = syside.ModelPrinter.sysml()
sysml_text = syside.pprint(root_namespace, printer, printer_cfg)


Thanks, I can reproduce it now. The crash was due to deserialization of Memberships failing when they referenced external elements (unresolved references). Fixed both the crash which now throws an error instead, and deserialization of such Memberships for the next release.