I have a piece of code that does the following:
lsheet, rsheet = db.get(Sheet, {'_id': left['sheetId']}), \
db.get(Sheet, {'_id': right['sheetId']})
print('saving %s with primary key %s.' % (lsheet.title, lsheet._id))
db.save(lsheet)
db.save(rsheet)
print('saved.')
At the moment the first line is printed, the lsheet object has an _id (the pk is called _id in this class, that's working correctly in other parts of the script). But then the call fails with
Traceback (most recent call last):
File "test.py", line 3, in <module>
db = make_db('data/20160422.json')
File "/home/fiatjaf/comp/hack-json/db.py", line 105, in make_db
db.save(lsheet)
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/backends/file/backend.py", line 459, in save
serialized_attributes = self.serialize(obj.attributes)
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/backends/base.py", line 159, in serialize
output_obj[str(key) if convert_keys_to_str else key] = serialize_with_opts(value, embed_level=embed_level)
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/backends/base.py", line 150, in <lambda>
serialize_with_opts = lambda value,*args,**kwargs : self.serialize(value,*args,convert_keys_to_str = convert_keys_to_str,autosave = autosave,for_query = for_query, **kwargs)
File "/home/fiatjaf/compk/hack-json/venv/lib/python3.4/site-packages/blitzdb/backends/base.py", line 161, in serialize
output_obj = list(map(lambda x: serialize_with_opts(x, embed_level=embed_level), obj))
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/backends/base.py", line 161, in <lambda>
output_obj = list(map(lambda x: serialize_with_opts(x, embed_level=embed_level), obj))
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/backends/base.py", line 150, in <lambda>
serialize_with_opts = lambda value,*args,**kwargs : self.serialize(value,*args,convert_keys_to_str = convert_keys_to_str,autosave = autosave,for_query = for_query, **kwargs)
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/backends/base.py", line 175, in serialize
obj.save(self)
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/document.py", line 390, in save
return backend.save(self)
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/backends/file/backend.py", line 456, in save
if hasattr(obj, 'pre_save') and callable(obj.pre_save):
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/document.py", line 175, in __getattribute__
self.revert()
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/document.py", line 427, in revert
raise self.DoesNotExist("No primary key given!")
blitzdb.document.DoesNotExist: DoesNotExist(Record)
The error happens at https://github.com/adewes/blitzdb/blob/master/blitzdb/document.py#L490. I put some print() calls there and inside the def pk(self) method and discovered that the object was empty. A call to self.keys() returns an empty list, that's why self.pk returns None. I don't know at which time the object becomes empty and couldn't find it myself.
I must say that basic saving, fetching and filtering is working well in many other parts of the script.
I have a piece of code that does the following:
At the moment the first line is printed, the
lsheetobject has an_id(thepkis called_idin this class, that's working correctly in other parts of the script). But then the call fails withThe error happens at https://github.com/adewes/blitzdb/blob/master/blitzdb/document.py#L490. I put some
print()calls there and inside thedef pk(self)method and discovered that the object was empty. A call toself.keys()returns an empty list, that's whyself.pkreturnsNone. I don't know at which time the object becomes empty and couldn't find it myself.I must say that basic saving, fetching and filtering is working well in many other parts of the script.