Skip to content

fix: Do not save null values for TEAV [DHIS2-21599]#24302

Merged
enricocolasante merged 3 commits into
masterfrom
DHIS2-21599
Jun 30, 2026
Merged

fix: Do not save null values for TEAV [DHIS2-21599]#24302
enricocolasante merged 3 commits into
masterfrom
DHIS2-21599

Conversation

@enricocolasante

Copy link
Copy Markdown
Contributor

Summary

Prevents the tracker importer from persisting tracked entity attribute values with a null/empty value, and enforces this at the database level by making trackedentityattributevalue.value NOT NULL. Previously, importing an empty value for an attribute that did not yet exist on the tracked entity inserted a meaningless row with a null/empty value instead of doing nothing.

Changes

  • AbstractTrackerPersister.handleTrackedEntityAttributeValues: adds the isDelete && isNew branch so that sending an empty value for an attribute with no existing value is a no-op. Before this, valueChanged was true for new entries, so the empty value fell through to saveOrUpdateAttributeValue and inserted a row with a null/empty value.
  • TrackedEntityAttributeValue.hbm.xml: marks the value property not-null="true", aligning the Hibernate mapping with the new DB constraint.
  • New migration 2.44/V2_44_15__teav_value_not_null.sql: deletes any pre-existing rows where value IS NULL (legacy/orphan data — the encryption encryptedvalue column was already removed in V2_44_6), then applies ALTER COLUMN value SET NOT NULL. Empty string ('') is intentionally still allowed.
  • TrackedEntityAttributeTest: adds two regression tests — one asserting that importing an empty value for an attribute not in the DB persists no row (isDelete && isNew), and a companion asserting that importing an empty value for an existing attribute deletes its row while leaving the others untouched (isDelete && !isNew).

@enricocolasante enricocolasante requested a review from a team as a code owner June 29, 2026 11:17
enricocolasante and others added 2 commits June 30, 2026 11:25
…s/bundle/persister/AbstractTrackerPersister.java

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

Copy link
Copy Markdown

@enricocolasante enricocolasante merged commit d8dafd1 into master Jun 30, 2026
23 checks passed
@enricocolasante enricocolasante deleted the DHIS2-21599 branch June 30, 2026 09:55
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.

3 participants