gjhiggins/rdflib — Issue #81: ZODB backend fails to remove triples
Author: gjhiggins
Created: 2011-10-19 01:14:46+00:00
State: open

Originally filed by jus...@onebrightspace.com on 2009-09-01T09:29:08

What steps will reproduce the problem?
1. Use ZODB backend.
2. Add a number of triples.
3. call remove((None, None, None))

What is the expected output? What do you see instead?
Expected: All triples removed
Actual: Only a percentage of the triples are removed.

What version of the product are you using? On what operating system?
2.4.1

Please provide any additional information below.
The ZODB backend uses IOMemory. The remove() method calls triples() to get
a list of triples to remove. The triples method yields the results from a
{}.keys(); which is normally a list in Python, however on a BTree this
results in an iterable object. Because the remove() method is then looping
around an iterable list and not a static list, the size of the list shrinks
as items are removed, resulting in missed triples and general odd behaviour.

Fix is to explicitly list() the tiples call in remove:

for triple, cg in list(self.triples(triple)):

This may be a rather large list, but the alternative is to list() the
keys() call in the triples method. The triple method is likely to be used
a lot more than remove, so forcing it to list everything on the keys() call
will slow it down.