Comments (8)
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)
from blitzdb.
Thanks for reporting this! Can you send me a full code example of your Record
class? When I do the following:
import blitzdb
doc = blitzdb.Document()
doc.attributes
it works as expected.
In your example I see that you set the pk
value of your record(through initialize
?), which tells BlitzDB that the object should exist in the database, so when you call attributes
it tries to fetch it from there, which fails as there is no object with that given primary key.
It's hard to tell if it's a BlitzDB bug or some problem with your Record
class, but if you can provide a more complete example I think I'd be better able to help you.
from blitzdb.
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 18
there, if we change it to 300 or something bigger, then the code always fails, but if we change it to 1
or 2
then it never fails.
It fails when printing r.attributes
, which means a Record
r
actually is saved, but it has a blank .pk
, and so its .attributes
cannot be fetched, then the program errors
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.
from blitzdb.
Thanks for reporting this @fiatjaf , I'll have a look at it this week!
from blitzdb.
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.
from blitzdb.
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.
from blitzdb.
No I think the problem is that the FileBackend does not yet support having a different name (_id
) for the primary key field. I will write some unit tests for this and implement the behavior as intended in the coming days.
from blitzdb.
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.
from blitzdb.
Related Issues (20)
- $exists still works wrong HOT 2
- hidden attribute
- except without action
- method could be a function HOT 1
- Add unique indices HOT 2
- hidden attribute
- Update the documentation website with the latest changes HOT 1
- Installing 0.2.12 through pip doesn't install 'six' module. HOT 1
- SyntaxError when importing Document and/or FileBackend HOT 1
- Filter expressions example from README fails for file backend HOT 1
- Merge two databases? HOT 2
- Issue with config file being overwritten
- object file not saved HOT 1
- Missing dependency info on PyPI
- getting error when using MongoBackend HOT 1
- Syntax for Keyword Searching (LIKE in SQL) HOT 2
- Support for ujson HOT 1
- OrderedDict turns to normal dict when document is loaded from database HOT 1
- SqlBackend doesn't support querying without indexes, but it also can't create indexes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blitzdb.