fix(adminui): the MQTT tag editor writes a meaningless payloadFormat into a Sparkplug tag blob #513

Closed
opened 2026-07-27 13:50:31 -04:00 by dohertj2 · 1 comment
Owner

MqttTagConfigEditor writes a payloadFormat key into the tag's TagConfig JSON even when the tag is in
SparkplugB mode, where the key has no meaning — payloadFormat (Json/Raw/Scalar) is a Plain-mode
concept.

Cosmetic only, and confirmed so. The tag factory routes Sparkplug tags on the Sparkplug keys
(groupId/edgeNodeId/deviceId/metricName) and ignores payloadFormat entirely, so nothing is
mis-bound — the value is noise in the stored blob, not a behaviour.

Why fix it anyway. The blob is operator-visible (it is what the raw-JSON textarea shows and what a config
export contains), and a key that looks like it selects a decode path but does not is a trap for the next
person reading a Sparkplug tag's config — including anyone diagnosing a decode problem.

Fix. Have the editor's ToJson omit payloadFormat when mode is SparkplugB. Keep the
preserve-unknown-keys behaviour intact (the editors deliberately round-trip keys they do not own — do not let
this change start dropping foreign keys).

Acceptance. A Sparkplug tag authored through the editor round-trips without a payloadFormat key; a Plain
tag still carries it; unknown keys are still preserved on both paths.

`MqttTagConfigEditor` writes a `payloadFormat` key into the tag's `TagConfig` JSON even when the tag is in **SparkplugB** mode, where the key has no meaning — `payloadFormat` (`Json`/`Raw`/`Scalar`) is a **Plain**-mode concept. **Cosmetic only, and confirmed so.** The tag factory routes Sparkplug tags on the Sparkplug keys (`groupId`/`edgeNodeId`/`deviceId`/`metricName`) and ignores `payloadFormat` entirely, so nothing is mis-bound — the value is noise in the stored blob, not a behaviour. **Why fix it anyway.** The blob is operator-visible (it is what the raw-JSON textarea shows and what a config export contains), and a key that looks like it selects a decode path but does not is a trap for the next person reading a Sparkplug tag's config — including anyone diagnosing a decode problem. **Fix.** Have the editor's `ToJson` omit `payloadFormat` when mode is SparkplugB. Keep the preserve-unknown-keys behaviour intact (the editors deliberately round-trip keys they do not own — do not let this change start dropping foreign keys). **Acceptance.** A Sparkplug tag authored through the editor round-trips without a `payloadFormat` key; a Plain tag still carries it; unknown keys are still preserved on both paths.
dohertj2 added the driver/mqtt label 2026-07-27 13:50:31 -04:00
Author
Owner

Fixed in master 2a7d1167.

MqttTagConfigModel.ToJson now writes payloadFormat in Plain mode only.

Sharper than the issue states, and worth recording. This was not preserving a retyped tag's
leftover — PayloadFormat is the one Plain field with a non-nullable typed backing, so
"write what the field says" invented "payloadFormat":"Json" in the blob of a Sparkplug tag that had
never carried one. Every other mode-inapplicable key (topic, jsonPath, groupId…) is blank-⇒-omit,
which is why none of them had the same problem.

Preserve-unknown-keys is unchanged and pinned: the retype test asserts the stale key is cleared while
isHistorized and an unrecognised key survive. Falsified by reverting the line — the two omission tests
go red, the Plain control stays green.

Fixed in master `2a7d1167`. `MqttTagConfigModel.ToJson` now writes `payloadFormat` in Plain mode only. **Sharper than the issue states, and worth recording.** This was not preserving a retyped tag's leftover — `PayloadFormat` is the one Plain field with a **non-nullable** typed backing, so "write what the field says" *invented* `"payloadFormat":"Json"` in the blob of a Sparkplug tag that had never carried one. Every other mode-inapplicable key (`topic`, `jsonPath`, `groupId`…) is blank-⇒-omit, which is why none of them had the same problem. Preserve-unknown-keys is unchanged and pinned: the retype test asserts the stale key is cleared *while* `isHistorized` and an unrecognised key survive. Falsified by reverting the line — the two omission tests go red, the Plain control stays green.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/lmxopcua#513