Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: FK constraint error when delete Program with MapView #19686

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

vietnguyen
Copy link
Contributor

@vietnguyen vietnguyen commented Jan 16, 2025

https://dhis2.atlassian.net/browse/DHIS2-18702

Issue:

  • Database throw FK constraint violation when deleting a Program which is referenced by MapView.

Fix

  • Remove the program reference from MapView.
  • The MapView table also has ProgramStage foreign key, so it also needed to be removed.
  • After deleting the Program, user might see an error when viewing the Map. If that happens, user can delete the Map in the Maps app.

Test

  • Added unit test.
  • Manual test steps are described in DHIS2-18702

Comment on lines 96 to 99
programStage -> {
if (mapView.getProgramStage().getUid().equals(programStage.getUid())) {
mapView.setProgramStage(null);
}
Copy link
Contributor

@jbee jbee Jan 16, 2025

Choose a reason for hiding this comment

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

This looks a bit like forEach abuse. If you want to set the program stage of the map-view null in case the program has a stage with the same ID as the map-view is using I think something like

if (mapView.getProgramStage() != null && program.getProgramStages().contains(mapView.getProgramStage()) {
   mapView.setProgramStage(null);
}            

is more clear. Maybe you want to compare IDs to be more safe that contains can be written similarly using program.getProgramStages().stream().map(IdentifiableObject::getUid).toList().containts...

@vietnguyen vietnguyen merged commit f4c8d17 into master Jan 16, 2025
17 checks passed
@vietnguyen vietnguyen deleted the DHIS2-18702-42 branch January 16, 2025 14:36
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