durusmail: durus-users: snag with btree.get(key)
snag with btree.get(key)
2005-07-07
2005-07-07
2005-07-07
2005-07-08
2005-07-08
2005-07-08
2005-07-08
2005-07-08
2005-07-11
2005-07-08
2005-07-08
2005-07-08
2005-07-08
Schevo and moellus [was: Re: [Durus-users] snag with btree.get(key)]
2005-07-11
Re: Schevo and moellus [was: Re: [Durus-users] snag with btree.get(key)]
2005-07-13
2005-07-14
2005-07-14
2005-07-14
2005-07-13
2005-07-07
snag with btree.get(key)
Mario Ruggier
2005-07-07
Hi,

i've hit a nasty problem with btrees...  it is demonstrated somewhat by
the code snippet below, that maybe could indicate to someone what might
be going wrong.

The problem is that, for the case when the key of an item in the btree
is a tuple (of anything, including other persistent (and persisted)
instances) then doing a btree.get(key) will sometimes return None !!

An example of what these tuple keys look like is:  (,
'Coach')
where  is a ref to a persisted instance ("stored" in some
other container).

However, first a little about the context...

I have a "main" btree per container, the key for which is an integer
id, completely managed by the framework. Doing btree_id.get(id) always
returns the item value correctly.

Then I have a btree per declared index on the container...  and there
is at least one of these, based on the keybinding attrs of the
container item class. Thus, for such indices, each item key is the
corresponding tuple of values, for the attrs listed in the keybindings
tuple for the item class (moellus talk ;-). For the item key example
above, the keybindings tuple would therefore be something like:
('person','role'). Doing a btree_kb.get(tuple_key) sometimes returns
the value correctly, sometimes returns None!

Obvious question is, are these complex tuple keys set correctly? Ok,
look at this loop (for the btree with keybinding values tuple as keys):

         for item in btree_kb.items():
             print item[0],     # a
             print item[1],     # b
             print btree.get(item[0]) # c
             #assert btree.get(item[0]) is not None
             #assert item[1] == btree.get(item[0])

The item (key,value) is always correct, and therefore the prints on
lines a and b are always what they should be. However, the print in
line c is sometimes None... and when it is not, it is always equal to
output of b.

I also have the impression that line c (for same item) gives None in
some conditions and the correct item under other conditions -- the only
difference I can think of is whether the item was previously loaded or
not... BTW, during all of this, there are no changes to the database
file.

The size of the containers seems to be irrelevant... the first one it
happens on only has 83 items. I am using BTree with the default
minimum_degree of 16.

Again, for the other btree, with simple integer ids, collecting exactly
the same set of instances, the above loop always produces the correct
output.

Plus, previously this keybindings index was using a persistent_dict,
with the same identical key tuples, and I never ran into any such
problems.

Any ideas of what may be happening?

mario

reply