Inverse property is not updated when referenced entity is destroyed

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Inverse property is not updated when referenced entity is destroyed

franzlst
A code snippet say more than a thousand words or so, so here is a code snippet that demonstrates what I think is an owlready2 bug:

from owlready2 import *

o1 = get_ontology("http://test.de/test")

with o1:
    class A(Thing):
        pass

    class B(Thing):
        pass

    class C(Thing):
        pass

    class a_to_b(ObjectProperty):
        domain = [A]
        range = [B]

    class b_to_c(ObjectProperty):
        domain = [B]
        range = [C]

    class c_to_b(ObjectProperty):
        domain = [C]
        range = [B]
        inverse_property = b_to_c

    a = A()
    b = B()
    c = C()

    a.a_to_b = [b]
    b.b_to_c = [c]
    assert c.c_to_b == [b]

    destroy_entity(b)

    assert a.a_to_b == []  # asserts to True
    assert c.c_to_b == []  # asserts to False

Two properties point to entity b, one is a "direct" property, one is an inverse property. When b is destroyed, the direct property is currectly updated, the inverse one is not.

I already had a look at the code: In triplelite.py, in destroy_entity (line 942), the modified relations that are collected are only the direct relations, not the inverse ones.
Reply | Threaded
Open this post in threaded view
|

Re: Inverse property is not updated when referenced entity is destroyed

franzlst
Here is a patch that fixes the issue for me. Don't know, if this is the right way to implement it, though :-)

fix_inverse_prop_bug.patch
Reply | Threaded
Open this post in threaded view
|

Re: Inverse property is not updated when referenced entity is destroyed

Jiba
Administrator
Hi,

Thank you for reporting and fixing this bug. I integrated your patch in the development version in a slightly modified version.

Jiba