Skip to content

Fix annotation updates when the end time changes - #2877

Open
nhoening wants to merge 7 commits into
mainfrom
fix/annotation-extending-existing
Open

nhoening wants to merge 7 commits into
mainfrom
fix/annotation-extending-existing

Conversation

@nhoening

Copy link
Copy Markdown
Member

Description

Posting an annotation with a changed end time can return HTTP 500. The lookup includes end and omits belief_time, while the database uniqueness constraint includes belief_time and excludes end. Extending an existing EV label from 07:00 to 07:15 therefore attempts a conflicting insert.

Align the lookup with the database identity: content, start, belief time, source and type. When an annotation already exists, update its end time and reuse it. Preserve separate annotations for different belief times.

Regression tests cover extending an annotation, repeating the request and preserving distinct belief times. The failure and fix were also reproduced locally using v1.1.1’s annotation model on an isolated SQLite database; the full server test suite has not been run.

Found while working on the HEMS script, as I made annotations longer.

  • fix updating/extending existing annotaitons - align annotation lookup…so it plays well with its database uniqueness constraint
  • Added changelog item in documentation/changelog.rst

… so it plays well with its database uniqueness constraint

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@nhoening nhoening added this to the 1.2.0 milestone Nov 17, 2026
@nhoening nhoening added the Data label Nov 17, 2026
nhoening and others added 4 commits November 18, 2026 18:32
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Annotation rows are shared by every account, asset and sensor they are linked to.
Re-posting a label with a prior and a different end to one sensor therefore also moved it on the other sensors showing it.
Only update the end when the annotation is linked to nothing but the annotated entity; otherwise, the POST endpoints now return 409.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>

@BelhsanHmida BelhsanHmida left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, tested: on main, re-posting a label with a prior and a later end gave a 500; with this branch it updates the end, and the new tests go red on main.

One thing I found: annotations are shared rows, so updating the end from sensor 2 also moved it on sensor 1. I pushed a fix: the end is only updated when nothing else shows the annotation, otherwise the API returns 409.
If you agree that's how annotations should behave, then the PR is approved.

BelhsanHmida and others added 2 commits November 24, 2026 03:31
…ing-existing

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@nhoening
nhoening requested a review from BelhsanHmida December 3, 2026 15:53

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants