Skip to content

[MS-1520] Don't send empty moduleIds in DeviceConfigurationUpdatedEvent - #1762

Open
BurningAXE wants to merge 1 commit into
mainfrom
MS-1520-don't-send-empty-moduleIds-in-DeviceConfigurationUpdated
Open

[MS-1520] Don't send empty moduleIds in DeviceConfigurationUpdatedEvent#1762
BurningAXE wants to merge 1 commit into
mainfrom
MS-1520-don't-send-empty-moduleIds-in-DeviceConfigurationUpdated

Conversation

@BurningAXE

@BurningAXE BurningAXE commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

JIRA ticket
Will be released in: 2026.3.0

Root cause analysis (for bugfixes only)

First known affected version: 2026.2.0

  • If selected moduleIds on the device are empty, it generates an event with an empty array (instead of null) for moduleIds but doesn't list them in tokenized fields (as there's nothing tokenized in there). However, the backend validation trips as it sees a path that should be tokenized but is not listed as such.

Notable changes

  • When moduleIds are empty - set the value to null instead of empty array so that JSON conversion omits it

Testing guidance

  • Login with a project configured with module partitioning but don't select modules
  • Go to settings and change language
  • Sync
  • Backend should not complain

Additional work checklist

  • Effect on other features and security has been considered
  • Design document marked as "In development" (if applicable)
  • External (Gitbook) and internal (Confluence) Documentation is up to date (or ticket created)
  • Test cases in Testiny are up to date (or ticket created)
  • Other teams notified about the changes (if applicable)

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

Fixes an event-sync validation issue where DeviceConfigurationUpdatedEvent could serialize downSyncModules as an empty array (rather than omitting the field), causing the backend to detect an untokenized tokenizable path.

Changes:

  • Normalize downSyncModules to null during setTokenizedListFields(...) when the tokenized list is empty, preventing empty-array serialization.
  • Add unit tests to ensure both null and empty-list module selections result in downSyncModules == null after tokenization.
  • Add an event-to-API mapping test to ensure downSyncModules is omitted from the serialized ApiEvent when no modules are selected.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
infra/events/src/main/java/com/simprints/infra/events/event/domain/models/DeviceConfigurationUpdatedEvent.kt Normalizes empty tokenized module list back to null to avoid emitting an empty array that triggers backend tokenization validation.
infra/events/src/test/java/com/simprints/infra/events/event/domain/models/DeviceConfigurationUpdatedEventTest.kt Adds coverage for setTokenizedListFields to ensure empty module lists remain/are converted to null.
infra/event-sync/src/test/java/com/simprints/infra/eventsync/event/usecases/MapDomainEventToApiUseCaseTest.kt Verifies API JSON omits downSyncModules (and produces no tokenizedFields) when modules are not selected.

@BurningAXE
BurningAXE marked this pull request as ready for review July 29, 2026 10:24
@BurningAXE
BurningAXE requested review from a team, TristramN, alex-vt, alexandr-simprints, luhmirin-s, meladRaouf and ybourgery and removed request for a team July 29, 2026 10:25
@BurningAXE
BurningAXE force-pushed the MS-1520-don't-send-empty-moduleIds-in-DeviceConfigurationUpdated branch from c936de6 to 42e6c2a Compare July 29, 2026 10:59
payload = payload.copy(
configuration = payload.configuration.copy(
downSyncModules = map[TokenKeyType.ModuleId] ?: payload.configuration.downSyncModules,
downSyncModules = (map[TokenKeyType.ModuleId] ?: payload.configuration.downSyncModules)?.ifEmpty { null },

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.

Wouldn't it be safer to fix it in TokenizeEventPayloadFieldsUseCase:23 by filtering/skipping any fields with empty lists?

That way we would not need to remember to apply the same fix for any list field in any future events.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I'll rework.

@BurningAXE
BurningAXE force-pushed the MS-1520-don't-send-empty-moduleIds-in-DeviceConfigurationUpdated branch from 42e6c2a to 50f10f4 Compare July 29, 2026 13:19
@BurningAXE
BurningAXE requested a review from Copilot July 29, 2026 13:22

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

infra/events/src/test/java/com/simprints/infra/events/event/domain/models/DeviceConfigurationUpdatedEventTest.kt:73

  • Test name says setTokenizableFields_* but the test actually calls setTokenizedListFields(...), which makes the intent misleading when reading failures. Rename the test to match the API under test.
    fun setTokenizableFields_keepsModuleIdsNullWhenMapHasNoModuleIds() {

infra/events/src/test/java/com/simprints/infra/events/event/domain/models/DeviceConfigurationUpdatedEventTest.kt:61

  • Test name says setTokenizableFields_* but the test actually calls setTokenizedListFields(...), which makes the intent misleading when reading failures. Rename the test to match the API under test.

This issue also appears on line 73 of the same file.

    fun setTokenizableFields_keepsExistingModuleIdsWhenMapHasNoModuleIds() {

@sonarqubecloud

Copy link
Copy Markdown

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.

3 participants