newtdb / db

Newt DB is a Python object-oriented database with JSONB-based access and search in PostgreSQL
http://www.newtdb.org
MIT License
143 stars 15 forks source link

AttributeError: 'Instance' object has no attribute 'update' #29

Open bmjjr opened 5 years ago

bmjjr commented 5 years ago

Hi, I'm trying to resolve below traceback:

Failed pickle load, oid: 1203, pickle starts: b'\x80\x03ctransistor.io.persistence.scraper_newt\nSplashCo'
Traceback (most recent call last):
  File "C:\ProgramData\Miniconda3\envs\pythonocc\lib\site-packages\newt\db\jsonpickle.py", line 509, in __call__
    state = unpickler.load()
  File "C:\ProgramData\Miniconda3\envs\pythonocc\lib\site-packages\newt\db\jsonpickle.py", line 242, in load
    getattr(self, op.name)(arg)
  File "C:\ProgramData\Miniconda3\envs\pythonocc\lib\site-packages\newt\db\jsonpickle.py", line 320, in SETITEMS
    for i in range(0, len(marked), 2)
  File "C:\ProgramData\Miniconda3\envs\pythonocc\lib\site-packages\newt\db\jsonpickle.py", line 123, in update
    self.v.update(v)
AttributeError: 'Instance' object has no attribute 'update'

Environment is Python 3.6.5 on Windows 10, at the point in time where the class is being saved to newt, at the final stage of a gevent routine.

The class object being saved is a fairly simple wrapper with class attributes containing basic data types, str(), dict(), and otherwise there is one JSON byte string which contains an html page and also a .png of the html page.

And finally, even though I get this error, I can't really find a side-effect of it, the object is still persisted to newt, and the data from the JSON byte string seems to be useable. For example, I can recreate the .png from the byte string, pulling it back out from the persisted newt.db object.

But after picking through it a few hours today and unable to resolve it, figured I'd report it here to see if it stands out. Just let me know if I can provide more info. Thank you.

bmjjr commented 5 years ago

To update. I used the dumps function in jsonpickle.py and it appears the problem is coming from the below OrderedDict:

od = OrderedDict([('user-agent', ('User-agent', 'python-requests/2.19.1 (MechanicalSoup/0.11.0)')), ('accept-encoding', ('Accept-Encoding', 'gzip, deflate')), ('accept', ('Accept', '*/*')), ('connection', ('Connection', 'keep-alive')), ('authorization', ('Authorization', b'Basic Yx5iOnJ1VG8lPR==')), ('content-length', ('Content-Length', '5935')), ('content-type', ('Content-Type', 'application/json'))])

A dumps(od) results in:

Traceback (most recent call last):
  File "C:\ProgramData\Miniconda3\envs\pythonocc\lib\site-packages\IPython\core\interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-131-62ab92dc09d6>", line 1, in <module>
dumps(od)
  File "C:\ProgramData\Miniconda3\envs\pythonocc\lib\site-packages\newt\db\jsonpickle.py", line 429, in dumps
sort_keys=True, indent=indent).replace(' \n', '\n')
  File "C:\ProgramData\Miniconda3\envs\pythonocc\lib\site-packages\newt\db\jsonpickle.py", line 242, in load
getattr(self, op.name)(arg)
  File "C:\ProgramData\Miniconda3\envs\pythonocc\lib\site-packages\newt\db\jsonpickle.py", line 320, in SETITEMS
for i in range(0, len(marked), 2)
  File "C:\ProgramData\Miniconda3\envs\pythonocc\lib\site-packages\newt\db\jsonpickle.py", line 123, in update
self.v.update(v)
AttributeError: 'Instance' object has no attribute 'update'