sqlitedict icon indicating copy to clipboard operation
sqlitedict copied to clipboard

Key ambiguity

Open Jwink3101 opened this issue 6 years ago • 7 comments

When using integer keys, they are converted to strings. Therefore:

mysqlitedict['1'] = 'ONE'
mysqlitedict[1] = 1

all refer to the same thing.

Jwink3101 avatar Mar 07 '18 17:03 Jwink3101

Just to add, it also can't handle tuple keys

Jwink3101 avatar Mar 07 '18 18:03 Jwink3101

@Jwink3101 thanks for the report & PR

CC: @piskvorky how this should work?

menshikh-iv avatar Mar 08 '18 06:03 menshikh-iv

IIRC there was a long discussion about encoding keys, and in the end we decided against it.

I don't remember the arguments any more, let me search through the issue history.

piskvorky avatar Mar 08 '18 08:03 piskvorky

The thread starts with #19 and continues all the way through #25, #26, #30 to #31 (closed as abandoned).

piskvorky avatar Mar 08 '18 08:03 piskvorky

In the changes of #74, byte/string keys are not modified. However, it appears as though the json encoding/decoding of the object may affect strings/bytes, especially on python2. I am not 100% sure of this behavior. But, it is worth noting again that this should not break any backwards compatibility as other keys are not touched.

As I mentioned also in #74, one remedy in general is to instead use the pickle of the object as the key but I think that is risky since, in my quick testing, while the unpickled object between py2.7 and 3.6 pass an equality check, they are not the same (even if you base64 encode them) and therefore would not be found.

Jwink3101 avatar Mar 08 '18 15:03 Jwink3101

@piskvorky through?

menshikh-iv avatar Mar 09 '18 05:03 menshikh-iv

Has anyone given this more consideration?

Jwink3101 avatar Oct 24 '18 15:10 Jwink3101