Emission: delete broker-side attributes that disappear locally - #150
Merged
Conversation
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.
There was a problem hiding this comment.
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}/attrsto a new refresh flow that appends viaPOST /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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
EmissionRefreshcollaborator:POST /entities/{id}/attrs(overwrite semantics), so newly appearing attributes land on old-spec brokers too.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:nullas 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
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.