Skip to content

fix: Do not save null values for TEAV [DHIS2-21599] (2.42)#24334

Open
enricocolasante wants to merge 4 commits into
2.42from
DHIS2-21599-2.42
Open

fix: Do not save null values for TEAV [DHIS2-21599] (2.42)#24334
enricocolasante wants to merge 4 commits into
2.42from
DHIS2-21599-2.42

Conversation

@enricocolasante

@enricocolasante enricocolasante commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Backport of DHIS2-21599 ("Do not save null values for TEAV", #24302) to the 2.42 branch.
As of this change, the tracker importer no longer persists tracked entity attribute values that
have no value. Unlike the master version, this backport does not ship a database migration to
clean up pre-existing null/empty attribute values; instead it adds a data integrity check that
surfaces those rows to administrators so they can be resolved manually. This keeps the stable 2.42
line free of automatic, irreversible data changes on upgrade.

Changes

  • Tracker import (AbstractTrackerPersister.java): no longer writes a tracked entity attribute
    value when the imported value is empty. An empty value for an existing attribute is treated as a
    delete; an empty value for an attribute not yet in the database is a no-op. The deleted entry is
    intentionally kept in the in-memory map so later occurrences of the same TE + attribute within the
    same import run still see it as existing (the DELETE is not flushed until the end of the run).

  • Data integrity check instead of a migration: adds
    data-integrity-checks/programs/tracked_entity_attribute_null_value.yaml and registers it in
    data-integrity-checks.yaml. The check flags any trackedentityattributevalue row whose value
    column is null or empty, distinguishing two cases:

    • rows that have an encryptedvalue but no plain text value (previously confidential
      attributes), and
    • rows that have neither a plain text nor an encrypted value.

    It is marked SEVERE / is_slow and its recommendation explains, per case, how to either recover
    the plain text or delete the affected rows — mirroring the 2.44 migration notes, but leaving the
    action in the administrator's hands rather than performing it automatically.

  • Tests:

    • DataIntegrityTrackedEntityAttributeNullValueControllerTest — new controller integration test
      covering the no-data, plain-value-present, empty-only, and encrypted-only cases. Anomalous rows
      are inserted via raw SQL because the service layer refuses to persist a null value.
    • TrackedEntityAttributeTest — adds import-level coverage, notably
      shouldNotPersistAttributeValueWhenImportingEmptyValueForAttributeNotInDb and
      shouldDeleteAttributeValueWhenImportingEmptyValueForExistingAttribute.
  • Housekeeping: bumps section_order of single_events_null_occurred_date.yaml from 3 to 6 to
    make room for the new check ordering in the Programs section.

enricocolasante and others added 4 commits July 1, 2026 14:51
* fix: Do not save null values for TEAV [DHIS2-21599]

* Update dhis-2/dhis-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/AbstractTrackerPersister.java

Co-authored-by: marc <marc@dhis2.org>

* Fix formatting

---------

Co-authored-by: marc <marc@dhis2.org>
@sonarqubecloud

sonarqubecloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

@enricocolasante enricocolasante requested a review from a team July 2, 2026 09:48
@enricocolasante enricocolasante marked this pull request as ready for review July 2, 2026 09:48
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.

1 participant