Python4Capella - Comparison of CapellaElements - regression?

Hello,
I am migrating from Capella 1.4.2 to Capella 6.1 and I am getting different API behavior when comparing two Capella elements or when traversing lists (JavaList).

I would have difficulty explaining the problem in English, so I suggest you look at the following code instead:

        LC1 = myProject.get_CapellaElement_by_id('bf320ea0-6f62-478d-a654-c04b63a152ff')
        LC2 = myProject.get_CapellaElement_by_id('bf320ea0-6f62-478d-a654-c04b63a152ff')
        
        jo_LC1 = LC1.get_java_object()
        jo_LC2 = LC2.get_java_object()
        
        print()
        print('LC1 =', LC1)
        print('LC2 =', LC2)
        print()
        print('LC1 is LC2:', LC1 is LC2)
        print('LC1 == LC2:', LC1 == LC2 )
        print('LC1 in [ LC2 ]:', LC1 in [ LC2 ])
        
        print()
        print('jo_LC1 =', jo_LC1)
        print('jo_LC2 =', jo_LC2)
        print()
        print('jo_LC1 is jo_LC2:', jo_LC1 is jo_LC2)
        print('jo_LC1 == jo_LC2:', jo_LC1 == jo_LC2)
        print('jo_LC1 in [ jo_LC2 ]:', jo_LC1 in [ jo_LC2 ])

Result on Capella 1.4.2

LC1 = myProject.get_CapellaElement_by_id(‘bf320ea0-6f62-478d-a654-c04b63a152ff’)
LC2 = myProject.get_CapellaElement_by_id(‘bf320ea0-6f62-478d-a654-c04b63a152ff’)

jo_LC1 = LC1.get_java_object()
jo_LC2 = LC2.get_java_object()

LC1 = <__main__.LogicalComponent object at 0x0000019A5DED4448>
LC2 = <__main__.LogicalComponent object at 0x0000019A5EC3AA88>

LC1 is LC2: False
LC1 == LC2: True
LC1 in [ LC2 ]: True

jo_LC1 = org.polarsys.capella.core.data.la.impl.LogicalComponentImpl@6a2138e2 (id: bf320ea0-6f62-478d-a654-c04b63a152ff, sid: null) (name: Composant_A1) (visibleInDoc: true, visibleInLM: true, summary: null, review: null) (abstract: false, actor: false, human: false)
jo_LC2 = org.polarsys.capella.core.data.la.impl.LogicalComponentImpl@6a2138e2 (id: bf320ea0-6f62-478d-a654-c04b63a152ff, sid: null) (name: Composant_A1) (visibleInDoc: true, visibleInLM: true, summary: null, review: null) (abstract: false, actor: false, human: false)

jo_LC1 is jo_LC2: False
jo_LC1 == jo_LC2: True
jo_LC1 in [ jo_LC2 ]: True

Result on Capella 6.1

LC1 = myProject.get_CapellaElement_by_id(‘bf320ea0-6f62-478d-a654-c04b63a152ff’)
LC2 = myProject.get_CapellaElement_by_id(‘bf320ea0-6f62-478d-a654-c04b63a152ff’)

jo_LC1 = LC1.get_java_object()
jo_LC2 = LC2.get_java_object()

LC1 = <__main__.LogicalComponent object at 0x0000026E31980D90>
LC2 = <__main__.LogicalComponent object at 0x0000026E318A6950>

LC1 is LC2: False
LC1 == LC2: False
LC1 in [ LC2 ]: False

jo_LC1 = LogicalComponent[TRANSIENT]
jo_LC2 = LogicalComponent[TRANSIENT]

jo_LC1 is jo_LC2: False
jo_LC1 == jo_LC2: True
jo_LC1 in [ jo_LC2 ]: True

You changed the version of Capella between your two tests but did you change the version of Python for Capella or the Python interpreter ?

One thing that could explain the change is this issue:

But it should not return false for LC1 == LC2… It delegates the comparison to Java and should return the same as jo_LC1 == jo_LC2.

I made the test on my side (Capella 7.0.0, Python for Capella 1.3.0 and Python 3.11) and get the following result:

LC1 = <__main__.SystemEngineering object at 0x7e57ba6326d0>
LC2 = <__main__.SystemEngineering object at 0x7e57ba633790>

LC1 is LC2: False
LC1 == LC2: True
LC1 in [ LC2 ]: True

jo_LC1 = org.polarsys.capella.core.data.capellamodeller.impl.SystemEngineeringImpl@1a75c337 (id: 8f49452e-61f2-4ba0-b944-352d1f4c4227, sid: null) (name: In-Flight Entertainment System) (visibleInDoc: true, visibleInLM: true, summary: null, review: null)
jo_LC2 = org.polarsys.capella.core.data.capellamodeller.impl.SystemEngineeringImpl@1a75c337 (id: 8f49452e-61f2-4ba0-b944-352d1f4c4227, sid: null) (name: In-Flight Entertainment System) (visibleInDoc: true, visibleInLM: true, summary: null, review: null)

jo_LC1 is jo_LC2: True
jo_LC1 == jo_LC2: True
jo_LC1 in [ jo_LC2 ]: True

Which is correct. The operator is in Python is the identity comparison aka the same object in memory, that’s why it return False while the == operator return True by delegating to __eq__() and Java equals() method.

After testing with Team for Capella I have the following results:

Local

LC1 = <__main__.SystemEngineering object at 0x7a33859ca2d0>
LC2 = <__main__.SystemEngineering object at 0x7a337e59fad0>

LC1 is LC2: False
LC1 == LC2: True
LC1 in [ LC2 ]: True

jo_LC1 = SystemEngineering[TRANSIENT]
jo_LC2 = SystemEngineering[TRANSIENT]

jo_LC1 is jo_LC2: True
jo_LC1 == jo_LC2: True
jo_LC1 in [ jo_LC2 ]: True

Team for Capella

LC1 = <__main__.SystemEngineering object at 0x725a4417fa10>
LC2 = <__main__.SystemEngineering object at 0x725a43e4b1d0>

LC1 is LC2: False
LC1 == LC2: True
LC1 in [ LC2 ]: True

jo_LC1 = SystemEngineering@OID217
jo_LC2 = SystemEngineering@OID217

jo_LC1 is jo_LC2: True
jo_LC1 == jo_LC2: True
jo_LC1 in [ jo_LC2 ]: True

It doesn’t reproduce your issue…

Thank you for the explanations.
We indeed do not have the same behavior.
I have not redefined the __eq__ method and I prefer not to do it.

OK, you probably need to update to Python for Capella 1.3.0 then. You can also apply the change on Python for Capella 1.2.0 and test if it fix the problem.