sqlitedict
sqlitedict copied to clipboard
Key ambiguity
When using integer keys, they are converted to strings. Therefore:
mysqlitedict['1'] = 'ONE'
mysqlitedict[1] = 1
all refer to the same thing.
Just to add, it also can't handle tuple keys
@Jwink3101 thanks for the report & PR
CC: @piskvorky how this should work?
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.
The thread starts with #19 and continues all the way through #25, #26, #30 to #31 (closed as abandoned).
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.
@piskvorky through?
Has anyone given this more consideration?