Miserlou / NoDB

NoDB isn't a database.. but it sort of looks like one.
https://blog.zappa.io/posts/introducing-nodb-pythonic-data-store-s3
380 stars 45 forks source link

Remove unnecessary .encode when writing to cache #24

Closed wbernoudy closed 5 years ago

wbernoudy commented 5 years ago

Issue

The body of an object is read in as bytes in python 3 (at least sometimes?). When the cache option is on, NoDB will then attempt to call .encode() on these bytes and then write that to the cache file. However this method was removed in python 3, so error something like:

  File "/opt/conda/lib/python3.6/site-packages/nodb/__init__.py", line 145, in load
    in_file.write(serialized.encode(self.encoding))
AttributeError: 'bytes' object has no attribute 'encode'

is raised.

Solution

I think simply removing the .encode() should be fine, as python 2/3 can write bytes or str to a file just fine. Let me know if I have misunderstood what that line is supposed to be doing.

coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 56.738% when pulling 3b19a6b28399f0f6eb6066c30c22bad745964b2e on wbernoudy:python3-cache-fix into 46169217e84b6e72c17a94ef96e3bf84183d45bc on Miserlou:master.

bendog commented 5 years ago

I feel like there might be a reason for this, it might be for python <= 3.5 compatibility.

bendog commented 5 years ago

replaced the code with non-breaking fix in #27