simphony / simphony-osp

A framework that aims to achieve interoperability between software such as simulation engines, databases and data repositories using a knowledge graph as the common language.
https://simphony.readthedocs.io
Other
16 stars 12 forks source link

Strange behaviour of CUDS remove #638

Closed paulzierep closed 3 years ago

paulzierep commented 3 years ago

In the following case, shouldn't the object be removed from the DB ?

with SqliteWrapperSession("A.db") as session_A:
    wrapper = cuba.Wrapper(session=session_A)

    wrapper.add(cuba.Entity(), rel=cuba.activeRelationship)

    session_A.commit()

with SqliteWrapperSession("A.db") as session_A:
    wrapper = cuba.Wrapper(session=session_A)

    for cuds in wrapper.iter():
        wrapper.remove(cuds)
        #wrapper.session.delete_cuds_object(cuds)

    session_A.commit()

with SqliteWrapperSession("A.db") as session_A:
    wrapper = cuba.Wrapper(session=session_A)

    pretty_print(wrapper)

##################################################

- Cuds object:
  uuid: 5b4726ff-bff5-401e-9ffa-a8cf2f2d4033
  type: cuba.Wrapper
  superclasses: cuba.Entity, cuba.Wrapper
  description: 
    The root of all wrappers. These are the bridge to simulation engines and databases.

   |_Relationship cuba.activeRelationship:
     -  cuba.Entity cuds object:
        uuid: 938f89ee-2819-4695-a886-2e270663598f

If I use the wrapper.session.delete_cuds_object(cuds) function pretty_print(wrapper) drows an arrow:

  File "session_exchange/remove_from_DB.py", line 36, in <module>
    pretty_print(wrapper)
  File "osp/core/utils/pretty_print.py", line 27, in pretty_print
    pp += _pp_subelements(cuds_object)
  File "osp/core/utils/pretty_print.py", line 74, in _pp_subelements
    key=lambda x: (str(x[0].oclass), str(x[1]),
  File "osp/core/cuds.py", line 375, in iter
    yield from ((r, m) for m in mapping[r.uid])
AttributeError: 'NoneType' object has no attribute 'uid'

How can I remove a CUDS from the DB ?

yoavnash commented 3 years ago

Could be related to #624. @kysrpex What do you think?

paulzierep commented 3 years ago

Yes it seems that wrapper.session.delete_cuds_object is related to #624. But how about wrapper.remove(cuds) should it not remove the object from the wrapper ?

pablo-de-andres commented 3 years ago

For completeness, could you add the whole error stack from the pretty_print?

paulzierep commented 3 years ago

Updated my comment