Code Monkey home page Code Monkey logo

Comments (8)

fiatjaf avatar fiatjaf commented on August 22, 2024

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.

adewes avatar adewes commented on August 22, 2024

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.

fiatjaf avatar fiatjaf commented on August 22, 2024

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.

adewes avatar adewes commented on August 22, 2024

Thanks for reporting this @fiatjaf , I'll have a look at it this week!

from blitzdb.

adewes avatar adewes commented on August 22, 2024

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.

fiatjaf avatar fiatjaf commented on August 22, 2024

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.

adewes avatar adewes commented on August 22, 2024

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.

nickjpg avatar nickjpg commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.