Skip to content

Wrong _last_id when opening an existing database #34

@domeav

Description

@domeav

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions