Skip to content

Right node inaccessible after deleting parent #52

@jsandbrook

Description

@jsandbrook

Apologies if I'm stating that incorrectly. I don't have the best handle on the inner workings of this library.

When a covering node has 'right' and 'left' nodes, deleting it makes the right prefix inaccessible. It's fairly easy to reproduce. [1]

This specifically happens with version 0.10.0 installed explicitly without the C extension. With the C-extension, it works as expected [2].

[1] No c-extension

# Setup
>>> import radix._radix
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'radix._radix'

>>> import radix
>>> radix.__version__
'0.10.0'
>>> rt = radix.Radix()
>>> rt.add('1.2.2.0/23')
<1.2.2.0/23>
>>> rt.add('1.2.2.0/24')
<1.2.2.0/24>
>>> rt.add('1.2.3.0/24')
<1.2.3.0/24>

# Check that the covering node has a right and left
>>> node = rt.search_exact('1.2.2.0/23')
>>> node.right
<1.2.3.0/24>
>>> node.left
<1.2.2.0/24>

# Delete the covering node
>>> rt.delete('1.2.2.0/23')

# The right node is no longer accessible despite still existing within nodes()
>>> rt.nodes()
[<1.2.2.0/24>, <1.2.3.0/24>]
>>> rt.search_exact('1.2.3.0/24')
>>> rt.delete('1.2.3.0/24')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/www/netarch-rest/ab-www/app/radix/radix.py", line 446, in delete
    raise KeyError('match not found')
KeyError: 'match not found'

[2] C-Extension exists this time

>>> import radix._radix
>>> rt = radix.Radix()
>>> rt.add('1.2.2.0/23')
<_radix.RadixNode object at 0x7fb361bda390>
>>> rt.add('1.2.2.0/24')
<_radix.RadixNode object at 0x7fb361bda420>
>>> rt.add('1.2.3.0/24')
<_radix.RadixNode object at 0x7fb361bda468>
>>> node = rt.search_exact('1.2.2.0/23')
>>> node.right
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: '_radix.RadixNode' object has no attribute 'right'
>>> node.left
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: '_radix.RadixNode' object has no attribute 'left'
>>> rt.delete(node.prefix)
>>> rt.search_exact('1.2.3.0/24')
<_radix.RadixNode object at 0x7fb361bda468>
>>> rt.delete('1.2.3.0/24')
>>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions