sqlitedict icon indicating copy to clipboard operation
sqlitedict copied to clipboard

Pull request proposal: Fixing the python 2->3 UnicodeError

Open shirish93 opened this issue 9 years ago • 0 comments

Hello,

The python2-> python3 break in pickling has caused many a developer much headache. While trying to get my SqliteDict from Py2 to Py3 the other day, I encountered the unicodeError that is caused by this issue. After a little research, I discovered that adding an encoding parameter to the loads and setting it to 'bytes' solves the issue. That's a simple change in line 105 of sqlitedict.py.

I'm raising this issue for general awareness, and not to jump the PR out of nowhere. : ) Since I encountered the issue after the latest release, I'm fairly certain it's not been fixed as of yet.

I present to you the simple tests I performed in Py3 to check that the change does not break anything. Everything prints as expected below. (Sorry for the formatting error. Can't seem to get code formatting to work). `

Test 1:

a = pickle.dumps("This is a test to check byte encoding does not break Py3 ") b = pickle.loads(a, encoding = 'bytes') print (b)

Test2:

pickle.dump("This is another test", open('temp.txt', 'wb')) print (pickle.load(open('temp.txt', 'rb'), encoding = 'bytes') `

Update: I don't have Python 2.7 access currently, but Ideone seems to give a runtime error for Test 1. In such a case, a parameter to the SqliteDict function, something like legacy = True, might have to be added? Will confirm when I get home.

shirish93 avatar Jan 26 '16 14:01 shirish93