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

Wrong _last_id when opening an existing database #34

Closed
domeav opened this Issue Oct 14, 2014 · 3 comments

Comments

2 participants
@domeav

domeav commented Oct 14, 2014

TinyDB version 2.0.1. My interpreter session:

from tinydb import TinyDB
db = TinyDB('my_existing_db.json')
len(db) # => 314
print db._last_id # => 99 (which is obviously wrong, as _get_next_id will return an existing id, messing with existing data)

Ids are actually sorted alphabetically.Table.init, so '99' is the last one. A workaround (albeit perhaps not the best one) is to replace line 191:

all_ids = sorted(self._read().keys())

by the following:

all_ids = sorted(self._read().keys(), key=int)

I find it strange I'm the first to notice this issue.

@msiemens msiemens closed this in 1e865a8 Oct 14, 2014

@msiemens

This comment has been minimized.

Show comment
Hide comment
@msiemens

msiemens Oct 14, 2014

Owner

Thanks for reporting and finding the cause!

Owner

msiemens commented Oct 14, 2014

Thanks for reporting and finding the cause!

@msiemens

This comment has been minimized.

Show comment
Hide comment
@msiemens

msiemens Oct 14, 2014

Owner

Fixed in the just released v2.1.0.

Owner

msiemens commented Oct 14, 2014

Fixed in the just released v2.1.0.

@domeav

This comment has been minimized.

Show comment
Hide comment
@domeav

domeav Oct 15, 2014

Wow, that was fast :-)

domeav commented Oct 15, 2014

Wow, that was fast :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment