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 updating a location's parent via UI #1217

Closed
Tracked by #1588
mahalakshme opened this issue May 8, 2024 · 4 comments
Closed
Tracked by #1588

Fix updating a location's parent via UI #1217

mahalakshme opened this issue May 8, 2024 · 4 comments
Assignees

Comments

@mahalakshme
Copy link
Contributor

mahalakshme commented May 8, 2024

Need:

Currently when a parent of a location is updated via UI it is not handled correctly. The subjects of the updated locations are not marked for migration and hence could lead to association error. Could be one of the reasons why some association errors for which root cause could not be determined has happened.

Technical analysis:

  • Marking all the subjects for migration might not be a scalable solution. As an alternative, we can find out the users for which reset sync can be done, based on the location hierarchy change. This can be done using virtual_catchment_address_mapping_table or catchment_address_mapping. On some analysis here, catchment_address_mapping seems to be faster. The decision is upto the developer.
  • Also to maintain uniformity of code, refer ResetSyncService.java -> recordCatchmentChange() in avni_server

AC:

Identify the users to be marked for complete reset sync using the below strategy: Say, A's parent is updated to B from C

if any of A or A's children have subjects registered in it then,
- check for users with catchments which have any of (B's location, any of the B's parents' locations, C, any of C's parent locations)
- mark the users for complete reset sync
else if neither of A or A's children have subjects registered then,
- no need to mark any of the users for reset sync

Out of scope:

Identifying more smart strategies to minimise the impact of reset sync.

Old: ignore


Need:

We 've not handled updating of location parent correctly. The subjects of the updated locations are not marked for migration and hence could lead to association error. Could be one of the reasons why some association errors for which root cause could not be determined has happened. This can be achieved by creating the locations in destination + deleting of the old locations. So no need to support this, since technically supporting this as well is not easy.

AC:

Disable updating location's parent for already created locations.

  • Like shown in the below screenshot, disable updating parent similar to type.
Screenshot 2024-05-20 at 4 17 51 PM

Old: ignore

Steps to reproduce:

env: staging org: RWB_Niti
current status of locations: Akola is under Maharashtra, and it contains Patur Taluka

  • Go to Admin -> Upload
  • Upload this file to change the parent of Akola to dummy1
    edit_location_edit_rwb_2.csv
  • Akola's parent gets updated, but lineage of Patur still says its State is Maharashtra

AC:

  • Do not allow parent of a location to get updated. Just update the same parent as parent of the location, not the the new one mentioned in the CSV
  • No need to handle/show error since this is not a common case. It is just that we should not allow to avoid corrupted data.

Suggestions:

  • so far needed for 2 cases: RWB(had children) and LFE(no children)
  • for no children/with children they need to move all the children to new location - if we remove this - then manual need to delete and create the location tree, updating of lineages need to handle
  • With children - also need to do updating last_modfied_date_time or inserting sub., migrations needed
  • So - we shud know and not reply on user reporting the error message to us - LocationMigration? if the migrated child or its children has subjects registered.

Inputs:

  • Introduce location migration
  • Wire this with API
  • Major change request
  • reset sync of all catchments where locations are associated with

Code reference:

https://github.com/avniproject/avni-server/blob/290e434960dd0e89a80f9d13859d1efdc0219ff8/avni-server-api/src/main/java/org/avni/server/importer/batch/csv/writer/LocationWriter.java#L151

Reference source card:

https://app.zenhub.com/workspaces/avni-product-deprecated-635b73bded85e50018871ae6/issues/gh/avniproject/avni-server/380

Analysis notes:

Not allowed because then need to update the lineage of all parents and then need to do reset sync for subjects of source and destination addresses. So as an alternative, new location can be created in the destination and /subjectMigrationBulk can be called via API or via code if we are gonna support. We can update the location parent from UI as well. Here as well we have not handled migration of subjects but we have done updateDescendantLocationLineage. So the question is should we support? We might get association errors if not handled.

@mahalakshme mahalakshme converted this from a draft issue May 8, 2024
@mahalakshme mahalakshme moved this from In Analysis to Analysis Complete in Avni Product May 8, 2024
@mahalakshme mahalakshme moved this from Analysis Complete to In Analysis Review in Avni Product May 8, 2024
@mahalakshme mahalakshme changed the title Do not allow to update the location parent via CSV Do not allow to update the location parent May 20, 2024
@mahalakshme mahalakshme changed the title Do not allow to update the location parent Do not allow to update the location parent via UI May 20, 2024
@mahalakshme mahalakshme moved this from In Analysis Review to Ready in Avni Product May 22, 2024
@himeshr himeshr moved this from Ready to In Progress in Avni Product May 27, 2024
@himeshr himeshr self-assigned this May 27, 2024
@mahalakshme mahalakshme moved this from In Progress to In Analysis in Avni Product May 27, 2024
@mahalakshme mahalakshme moved this from In Analysis to Ready in Avni Product May 27, 2024
@mahalakshme mahalakshme moved this from Ready to In Analysis Review in Avni Product May 27, 2024
@mahalakshme mahalakshme changed the title Do not allow to update the location parent via UI Fix updating a location's parent via UI May 29, 2024
@mahalakshme mahalakshme moved this from In Analysis Review to Ready in Avni Product May 30, 2024
@1t5j0y 1t5j0y moved this from Ready to In Progress in Avni Product May 30, 2024
@1t5j0y 1t5j0y self-assigned this May 30, 2024
1t5j0y added a commit to avniproject/avni-server that referenced this issue Jun 3, 2024
@1t5j0y 1t5j0y moved this from In Progress to Code Review Ready in Avni Product Jun 4, 2024
@petmongrels petmongrels moved this from Code Review Ready to In Code Review in Avni Product Jun 5, 2024
@petmongrels
Copy link
Contributor

Lets add integration test for this with valid scenarios.

@petmongrels petmongrels moved this from In Code Review to Code Review with Comments in Avni Product Jun 5, 2024
@1t5j0y 1t5j0y moved this from Code Review with Comments to In Progress in Avni Product Jun 10, 2024
1t5j0y added a commit to avniproject/avni-server that referenced this issue Jun 11, 2024
…eset sync records for applicable users when location parent is updated
@1t5j0y 1t5j0y moved this from In Progress to Code Review Ready in Avni Product Jun 11, 2024
@petmongrels petmongrels moved this from Code Review Ready to In Code Review in Avni Product Jun 24, 2024
@petmongrels petmongrels moved this from In Code Review to QA Ready in Avni Product Jun 24, 2024
@AchalaBelokar AchalaBelokar moved this from QA Ready to In QA in Avni Product Jul 2, 2024
@AchalaBelokar AchalaBelokar moved this from In QA to QA Ready in Avni Product Jul 2, 2024
@AchalaBelokar
Copy link

  • I tried to change this location with dummy1, Maharashtra with this csv

edit_location_edit_rwb_2.csv

got this error

errors-edit_location_edit_rwb_2 (1).csv

  • I tried with whole location change with lowest level still I got same error

@AchalaBelokar AchalaBelokar moved this from QA Ready to Done in Avni Product Jul 2, 2024
@AchalaBelokar AchalaBelokar moved this from Done to QA Failed in Avni Product Jul 3, 2024
@vinayvenu vinayvenu reopened this Jul 3, 2024
@github-project-automation github-project-automation bot moved this from QA Failed to Triaged in Avni Product Jul 3, 2024
@AchalaBelokar
Copy link

  • I login in to the AchalaB@rwbniti after that I chenge the state name of maharashtra which contain the akola district I change the state of akola district dummy1 .. and I login to client with AchalaB@rwbniti it is successfully login but after login I try to click on farmer it is showing this parent are mandatory for LocationMapping, Keys being saved - uuid,parent,child,voided. UUID: 85c1d940-c8cf-42f6-8af5-eead9765769f
    at create (address at index.android.bundle:1:1095483)
    at anonymous (address at index.android.bundle:1:1247189)
    at anonymous (address at index.android.bundle:1:1247102)
    at map ((native)::)
    at anonymous (address at index.android.bundle:1:1247088)
    at write ((native)::)
    at write (address at index.android.bundle:1:1095928)
    at bulkSaveOrUpdate (address at index.android.bundle:1:1247060)
    at persistAll (address at index.android.bundle:1:1582768)
    at processResponse (address at index.android.bundle:1:1585937)
    at anonymous (address at index.android.bundle:1:1586196)
    at tryCallOne (/root/react-native/packages/react-native/ReactAndroid/hermes-engine/.cxx/MinSizeRel/1h352kp3/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:53:16)
    at anonymous (/root/react-native/packages/react-native/ReactAndroid/hermes-engine/.cxx/MinSizeRel/1h352kp3/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:139:27)
    at apply ((native)::)
    at anonymous (address at index.android.bundle:1:247081)
    at _callTimer (address at index.android.bundle:1:246075)
    at _callReactNativeMicrotasksPass (address at index.android.bundle:1:246240)
    at callReactNativeMicrotasks (address at index.android.bundle:1:248162)
    at __callReactNativeMicrotasks (address at index.android.bundle:1:98201)
    at anonymous (address at index.android.bundle:1:97340)
    at __guard (address at index.android.bundle:1:98078)
    at flushedQueue (address at index.android.bundle:1:97251)
    at invokeCallbackAndReturnFlushedQueue (address at index.android.bundle:1:97194)

@AchalaBelokar AchalaBelokar moved this from Triaged to QA Failed in Avni Product Jul 3, 2024
@1t5j0y 1t5j0y moved this from QA Failed to In Progress in Avni Product Jul 3, 2024
@1t5j0y
Copy link
Contributor

1t5j0y commented Jul 4, 2024

Tried creating a minimal reproducible example but did not hit the above error after changing parent multiple times.

Scenario constructed:
User1 with Catchment1
User2 With Catchment2
Catchment1 with locations Country1
Catchment2 with locations Country2
Country1 hierarchy -> Country1, State1, District1, Village1
Country2 hierarchy -> Country2, State2, District2, Village2

Registered subjects in both Village1 and Village2.

Changed parent of State1 and State2 multiple times to Country1 and Country2 and verified reset sync was displayed and no error during sync for both users.

Moving this back to QA ready since sync behaviour was not changed as part of this card and unable to reproduce this error.

@1t5j0y 1t5j0y moved this from In Progress to QA Ready in Avni Product Jul 4, 2024
@AchalaBelokar AchalaBelokar moved this from QA Ready to In QA in Avni Product Jul 10, 2024
@AchalaBelokar AchalaBelokar moved this from In QA to Done in Avni Product Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

6 participants