Skip to content

Emission: delete broker-side attributes that disappear locally - #150

Merged
dkastl merged 2 commits into
mainfrom
feat/146-emission-null-deletion
Aug 5, 2026
Merged

Emission: delete broker-side attributes that disappear locally#150
dkastl merged 2 commits into
mainfrom
feat/146-emission-null-deletion

Conversation

@dkastl

@dkastl dkastl commented Aug 5, 2026

Copy link
Copy Markdown
Member

Closes #146. From the 2026-08 conformance audit.

Problem

The emitter upserts with POST /entities and fell back to PATCH /entities/{id}/attrs on 409. Attributes that disappear locally (assignee cleared, exposure switched off, geometry removed) were never deleted broker-side, so stale values persisted indefinitely. And on brokers implementing spec revisions <= 1.5, attributes added locally after the first emission never arrived, because those brokers ignore unknown attributes on the PATCH.

Approach

On 409 the update now runs through a new EmissionRefresh collaborator:

  1. Read back and diff. The broker's entity is fetched and its attribute names diffed against the current local representation. No new table or emission memory: fetch-and-diff needs no schema and self-heals when the broker was changed by someone else. A failed read-back skips the deletion pass for that run only.
  2. Append instead of PATCH. The attribute update moves to POST /entities/{id}/attrs (overwrite semantics), so newly appearing attributes land on old-spec brokers too.
  3. Per-attribute DELETE for stale attributes (CIM 009 clause 5.6.5), with 404 tolerated as the desired state.

Why not urn:ngsi-ld:null

The issue proposed the NGSI-LD null value (clause 4.5.0), and it was the first implementation here. Live verification against GeonicDB killed it: the broker does not implement the convention and stored the literal string urn:ngsi-ld:null as the attribute value, which is worse than the stale value it was meant to remove. The per-attribute DELETE has been in the spec since the earliest revisions and is unambiguous on every broker. The class comment documents this so the decision is not re-litigated blind.

Verification

  • Unit: emitter suite 14 → 19 runs (read-back conversation, per-attribute deletes, 404 tolerance, failed-delete logging, failed read-back still appends). Full plugin suite green.
  • Live against GeonicDB (gtt_fiware_dev): clearing assignee and description removed both attributes from the broker entity; re-adding the description brought it back through the append; the entity was fully removed on issue destroy.

When the create attempt answers 409 the update now runs through
EmissionRefresh, which reads the broker's entity back and diffs it against
the current local representation:

- the update itself moves from PATCH to POST /entities/{id}/attrs (append,
  overwrite semantics), so attributes that appeared locally after the first
  emission reach brokers that ignore unknown attributes on the PATCH (spec
  revisions <= 1.5)
- attributes the broker still has but the representation no longer carries
  are removed with per-attribute DELETEs (CIM 009 clause 5.6.5)

The urn:ngsi-ld:null value of clause 4.5.0 was the first candidate for the
deletions but is deliberately not used: brokers that do not implement the
convention store the null URN as a literal attribute value, which is worse
than the stale value it was meant to remove (GeonicDB does exactly that,
verified live 2026-08-05). The attribute DELETE is unambiguous everywhere.

Fetch-and-diff instead of a local memory of past emissions: no schema, and
it self-heals when the broker was changed by someone else. A failed
read-back skips the deletion pass for that run; the next update gets
another chance.

Verified live against GeonicDB (gtt_fiware_dev): clearing assignee and
description removed both attributes from the broker entity, re-adding the
description brought it back through the append.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the NGSI-LD emission “upsert” path so that when a broker reports an entity already exists (HTTP 409), the emitter refreshes the broker entity by appending current attributes and deleting broker-side attributes that no longer exist in the local representation (addressing stale attribute persistence and old-spec PATCH limitations).

Changes:

  • Replaces the 409 fallback from PATCH /entities/{id}/attrs to a new refresh flow that appends via POST /entities/{id}/attrs.
  • Adds fetch-and-diff against the broker entity to identify and delete stale attributes via per-attribute DELETE /entities/{id}/attrs/{name}, tolerating 404.
  • Expands emitter unit tests to cover read-back, append semantics, stale deletion, 404 tolerance, and failure handling.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/unit/emitter_test.rb Adds/updates unit tests covering the new 409 refresh flow (read-back, append, per-attribute delete, tolerance and failure cases).
lib/redmine_gtt_fiware/emitter.rb Switches 409 handling to delegate refresh behavior to EmissionRefresh.
lib/redmine_gtt_fiware/emission_refresh.rb Introduces a collaborator that GETs the broker entity, POSTs attribute updates, and DELETEs stale attributes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/redmine_gtt_fiware/emission_refresh.rb
@dkastl
dkastl merged commit da7f262 into main Aug 5, 2026
11 checks passed
@dkastl
dkastl deleted the feat/146-emission-null-deletion branch August 5, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emission: delete broker-side attributes that disappear locally (urn:ngsi-ld:null)

2 participants