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

Can not handle data by integer eid #45

Closed
wolfg1969 opened this Issue Jan 4, 2015 · 3 comments

Comments

2 participants
@wolfg1969
Contributor

wolfg1969 commented Jan 4, 2015

The id of the element will change to a unicode string after JSON serialization/deserialization. This causes no way to get the element by integer eid.

Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from tinydb import TinyDB
>>> db=TinyDB('/tmp/test.json')
>>> db.insert({'foo':'bar'})
1
>>> db.all()
[{u'foo': u'bar'}]
>>> element = db.all()[0]
>>> element.eid
u'1'
>>> assert db.get(eid=1) is not None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError
>>> assert db.get(eid='1') is not None
>>> db.update({'foo':'blah'}, eids=[1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/wolfg/.virtualenvs/opensource/lib/python2.7/site-packages/tinydb/database.py", line 335, in update
    cond, eids)
  File "/Users/wolfg/.virtualenvs/opensource/lib/python2.7/site-packages/tinydb/database.py", line 222, in process_elements
    func(data, eid)
  File "/Users/wolfg/.virtualenvs/opensource/lib/python2.7/site-packages/tinydb/database.py", line 334, in <lambda>
    self.process_elements(lambda data, eid: data[eid].update(fields),
KeyError: 1
>>> db.update({'foo':'blah'}, eids=['1'])
>>> db.all()
[{u'foo': u'blah'}]
>>> db.contains(eids=[1])
False
>>> db.contains(eids=['1'])
True
@eugene-eeo

This comment has been minimized.

Show comment
Hide comment
@eugene-eeo

eugene-eeo Jan 4, 2015

Contributor

Strange, I thought this behaviour was fixed in one of the commits. Would you be able to submit a pull request fixing this? It'll be trivial to implement, you might as well add a regression test along the way.

Contributor

eugene-eeo commented Jan 4, 2015

Strange, I thought this behaviour was fixed in one of the commits. Would you be able to submit a pull request fixing this? It'll be trivial to implement, you might as well add a regression test along the way.

@wolfg1969

This comment has been minimized.

Show comment
Hide comment
@wolfg1969

wolfg1969 Jan 4, 2015

Contributor

Okay. I'd like to fix it. Could you show me the previous commit?

Contributor

wolfg1969 commented Jan 4, 2015

Okay. I'd like to fix it. Could you show me the previous commit?

@eugene-eeo

This comment has been minimized.

Show comment
Hide comment
@eugene-eeo

eugene-eeo Jan 5, 2015

Contributor

Sorry, apparently I was mistaken, there is no commit that addresses this issue. But you should go ahead and fix it anyways.

Contributor

eugene-eeo commented Jan 5, 2015

Sorry, apparently I was mistaken, there is no commit that addresses this issue. But you should go ahead and fix it anyways.

@msiemens msiemens closed this in cb7c30e Jan 8, 2015

msiemens added a commit that referenced this issue Jan 8, 2015

Merge pull request #46 from wolfg1969/bugfix/get_by_eid
Fixing #45: JSON Backend converts IDs to strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment