Skip to content

SQLite IntegrityError while syncing #30

@JrtPec

Description

@JrtPec

Sometimes I run into this error while syncing a sensor:

File "D:\Python34\lib\site-packages\tmpo\__init__.py", line 253, in sync
    self._req_sync(sid, rid, lvl, bid)
  File "D:\Python34\lib\site-packages\tmpo\__init__.py", line 530, in _req_sync
    f.result(), sid, t["rid"], t["lvl"], t["bid"], t["ext"])
  File "D:\Python34\lib\site-packages\tmpo\__init__.py", line 546, in _write_block
    self.dbcur.execute(SQL_TMPO_INS, (sid, rid, lvl, bid, ext, now, blk))
sqlite3.IntegrityError: UNIQUE constraint failed: tmpo.sid, tmpo.rid, tmpo.lvl, tmpo.bid

My current solution is to just delete all TMPO-blocks for that sensor (see #27, implementation is on the way), after which I re-add the sensor and sync again. This causes a little bit of overhead, but it works fine.

However: doesn't this error just mean that the block we're trying to write already exists in the database? So we could deal with it in two ways:

  1. Assume the correct block is already written, so we can just ignore this insert.
  2. Assume the new block might be better, so overwrite the old one.

@icarus75 what do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions