-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attributes being deleted on .save() #64
Comments
In fact, no, there are other bizarre problems happening in other parts of the application. For example: >>> r
Record({})
>>> r.__dict__
{'_autoload': True, 'pk': '564a7c5dac00f40300a324ab', '_default_backend': <blitzdb.backends.file.backend.Backend object at 0x7f109d5a9320>, '_attributes': {}, '_lazy': True, 'embed': False}
>>> r.pk
>>> r.attributes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/document.py", line 164, in __getattribute__
self.revert()
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/document.py", line 424, in revert
raise self.DoesNotExist("No primary key given!")
blitzdb.document.DoesNotExist: DoesNotExist(Record) |
Thanks for reporting this! Can you send me a full code example of your
it works as expected. In your example I see that you set the It's hard to tell if it's a BlitzDB bug or some problem with your |
The issue has probably something to do with the size of the documents embedded in others. See this code: from blitzdb import Document
from blitzdb import FileBackend
class Sheet(Document):
class Meta(Document.Meta):
primary_key = '_id'
class Record(Document):
class Meta(Document.Meta):
primary_key = '_id'
db = FileBackend('/tmp/t.db')
sheet = Sheet({
'_id': '3i24i3l',
'something': 'papapa'
})
db.save(sheet)
db.commit()
sheet = db.get(Sheet, {'_id': '3i24i3l'})
sheet.records = []
for i in range(18):
record = Record({
'_id': '%s' % i,
'prop': 'parara'
})
sheet.records.append(record)
record.sheets = [sheet]
db.save(sheet)
db.save(record)
db.commit()
# ~
for s in db.filter(Sheet, {}):
print('sheet: ', s)
print('sheet: ', s.__dict__)
print('sheet: ', s.pk)
print('sheet: ', s.attributes)
for r in s.records:
print('record: ', r)
print('record: ', r.__dict__)
print('record: ', r.pk)
print('record: ', r.attributes)
r.pou = 'pôu'
db.save(r) This is the full runnable code. This code fails almost always in my machine. That number It fails when printing Traceback (most recent call last):
File "iso.py", line 48, in <module>
print('record: ', r.attributes)
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/document.py", line 164, in __getattribute__
self.revert()
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/document.py", line 425, in revert
obj = self._default_backend.get(self.__class__, {self.get_pk_name(): self.pk})
File "/home/fiatjaf/comp/hack-json/venv/lib/python3.4/site-packages/blitzdb/backends/file/backend.py", line 508, in get
raise cls.DoesNotExist
blitzdb.document.DoesNotExist: DoesNotExist(Record) This is the exact same situation that is happening in the first message of this issue thread. |
Thanks for reporting this @fiatjaf , I'll have a look at it this week! |
Hey @fiatjaf , I can reproduce the issue and I'm working on a fix. Currently arbitrary id names are not yet fully supported, I'm working on it though. |
Oh, should I be using integers? This would make it work? That would be ok, if I could know about it before, now I kind of gave up this project, so please don't do any unplanned hotfixes specific to this issue. |
No I think the problem is that the FileBackend does not yet support having a different name ( |
Any progress on this? Just ran into this bug on our installation of gitlab 8.10.4. Populate a "/var/opt/gitlab/git-data/repository//.git/info/attributes" file and after checking in an update the 'attributes' file is deleted and upload changes specified by 'attributes' not completed. |
I have a piece of code that does the following:
At the moment the first line is printed, the
lsheet
object has an_id
(thepk
is called_id
in 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.pk
returnsNone
. 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.
The text was updated successfully, but these errors were encountered: