avniproject / avni-server

Backend APIs for Avni
https://avniproject.org
GNU Affero General Public License v3.0
7 stars 25 forks source link

Bundle upload with no changes and report card updates breaking fresh sync #801

Closed mahalakshme closed 1 month ago

mahalakshme commented 1 month ago

Issue:

When some bundle upload made, - last_modified_date_time updated or just report card alone updated, then on fresh sync users will face the above issue - Soln: pace up the release

Steps to reproduce:

Need:

New/fresh sync users will face the error on sync: 'card are mandatory for DashboardSectionCardMapping, Keys being saved...' when a bundle from UAT to prod is uploaded

Tech Analysis:

1) One reason is what we insert as standard_report_card_input in migration and what is inserted via bundle import is different

AC:

- Do the changes in new release branch forked from 10.0.0 since 10.0.1 server testing will probably take more time

petmongrels commented 1 month ago

We cannot avoid last modified date time update as it is done by hibernate.

  1. The problem seems to be only in report card.
select last_modified_date_time, age(last_modified_date_time, created_date_time) from dashboard_filter order by last_modified_date_time desc;
select last_modified_date_time, age(last_modified_date_time, created_date_time) from dashboard_section order by last_modified_date_time desc;
select last_modified_date_time, age(last_modified_date_time, created_date_time) from dashboard_section_card_mapping order by last_modified_date_time desc;
select last_modified_date_time, age(last_modified_date_time, created_date_time) from dashboard order by last_modified_date_time desc;
select last_modified_date_time, age(last_modified_date_time, created_date_time) from report_card order by last_modified_date_time desc;
  1. Fix the last modified date time for report card to created date time value, if it is greater than our end of life date.
  2. Fix the existing database records to to use {"programs": [], "subjectTypes": [], "encounterTypes": []} instead of {}
mahalakshme commented 1 month ago

@petmongrels yeah agreed - we cant avoid the last_modified_date_time update -I had added that as soln when I thought we are updating the last_modified_date_time for some reason, even when there are no changes, later realised the issue after tech analysis

  1. How will existing users be able to sync the new changes done to report card.
mahalakshme commented 1 month ago

verified: production organisations are correctly marked as production in Category dropdown.

himeshr commented 1 month ago

Marking this card as 10.0 to be clear on where code changes are to be done, will use 10.0 branch offshot 10.0_hotfix for this.

mahalakshme commented 1 month ago

sure thanks @himeshr

mahalakshme commented 1 month ago

@himeshr dont know if reportDashboard.json will also update report card table in some cases - just sharing the scenarios that striked me.

himeshr commented 1 month ago

@himeshr dont know if reportDashboard.json will also update report card table in some cases - just sharing the scenarios that striked me.

Have handled all locations from where cardRepository.save() is invoked.

himeshr commented 1 month ago

Sample Error Responses as required after fix done in this card:

ReportCardBundleUploadError.csv

Screenshot 2024-10-09 at 2 32 47 PM Screenshot 2024-10-09 at 2 31 16 PM
himeshr commented 1 month ago

Made additional changes to block Create/Update/Delete for CustomDashboard related entities listed below:

himeshr commented 1 month ago

Currently, the only impact due to this issue is that Users Fresh Sync on old client will fail, in-case there is changes to reportCard and related entities after 26Sep2024. To handle this change, the data fix needed is to update lastModifiedDateTime to a value before 26Sep2024.

Not going ahead with the blocking approach, as we are not able to clearly reason out impact points and issues that might arise out of this change. Instead, see the changes being done as part of #802 to mitigate occurence of this error and a action plan to handle all future such errors.