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

Add client migration to remove the individual outside of user's catchment #1161

Closed
mahalakshme opened this issue Oct 31, 2023 · 6 comments
Closed
Assignees

Comments

@mahalakshme
Copy link
Contributor

mahalakshme commented Oct 31, 2023

Whats the issue:

The individual with uuid, 572b1b77-f886-4770-949b-d95a3959d232 is in some of the user's device though it doesn't belong to the users' catchment. Hence its lowestAddressLevel in realmdb is null. This is causing app crash when the user clicks on the individual card from say, the subject search results page.

Analysis:

  • The subject doesn't have any subject migrations
  • All functionalities related to reset sync are working as expected.
  • The individual is a valid entry and belongs to a different catchment.
  • The issue is not happening with any other individuals - identified from user's fast sync db.

To do:

  • Add a client migration to remove the individual with the above mentioned uuid, when its lowestAddressLevel is null.

Out of scope:

Identifying the root cause of the issue since enough time has been spent and now we have a non-null check added on realmdb tables to identify such issues ahead.

@mahalakshme mahalakshme converted this from a draft issue Oct 31, 2023
@mahalakshme mahalakshme moved this from In Analysis to In Analysis Review in Avni Product Oct 31, 2023
@mahalakshme mahalakshme moved this from In Analysis Review to Ready in Avni Product Oct 31, 2023
@ashusvnath ashusvnath self-assigned this Nov 1, 2023
@ashusvnath ashusvnath moved this from Ready to In Progress in Avni Product Nov 1, 2023
@ashusvnath
Copy link

based on discussions with @mahalakshme . making the migration independent of uuid.
all individuals with lowestAddressLevel = null will be removed.

ashusvnath pushed a commit to avniproject/avni-models that referenced this issue Nov 1, 2023
@ashusvnath ashusvnath moved this from In Progress to Code Review Ready in Avni Product Nov 1, 2023
@vinayvenu vinayvenu moved this from Code Review Ready to In Code Review in Avni Product Nov 2, 2023
@vinayvenu
Copy link
Member

I thought General.logDebug does not work in avni-models. In any case, not sure if it is a good idea to log in a loop.

Also, what happens to related objects when the individual is deleted?

@vinayvenu vinayvenu moved this from In Code Review to Code Review with Comments in Avni Product Nov 2, 2023
@ashusvnath ashusvnath moved this from Code Review with Comments to Analysis Complete in Avni Product Nov 2, 2023
@ashusvnath ashusvnath moved this from Analysis Complete to In Progress in Avni Product Nov 2, 2023
ashusvnath pushed a commit to avniproject/avni-models that referenced this issue Nov 2, 2023
…elated to individual along with individual
ashusvnath pushed a commit that referenced this issue Nov 2, 2023
@ashusvnath ashusvnath moved this from In Progress to Code Review Ready in Avni Product Nov 2, 2023
@petmongrels petmongrels moved this from Code Review Ready to In Code Review in Avni Product Nov 2, 2023
@petmongrels petmongrels moved this from In Code Review to Code Review Ready in Avni Product Nov 2, 2023
@petmongrels petmongrels moved this from Code Review Ready to In Code Review in Avni Product Nov 2, 2023
@petmongrels petmongrels moved this from In Code Review to Code Review Ready in Avni Product Nov 2, 2023
himeshr pushed a commit to avniproject/avni-models that referenced this issue Nov 3, 2023
…with lowestAddressLevel = null

(cherry picked from commit a205093)
himeshr pushed a commit to avniproject/avni-models that referenced this issue Nov 3, 2023
…elated to individual along with individual

(cherry picked from commit 3c9d21e)
@1t5j0y 1t5j0y moved this from Code Review Ready to In Code Review in Avni Product Nov 3, 2023
@1t5j0y
Copy link
Contributor

1t5j0y commented Nov 3, 2023

logging inside loop not addressed.

@1t5j0y 1t5j0y moved this from In Code Review to Code Review with Comments in Avni Product Nov 3, 2023
@ashusvnath
Copy link

@1t5j0y : I've left logging in place to aid debugging. i don't expect the number of such records to be high, and there's one log per record.

@1t5j0y 1t5j0y moved this from Code Review with Comments to QA Ready in Avni Product Nov 3, 2023
@1t5j0y 1t5j0y moved this from QA Ready to In QA in Avni Product Nov 6, 2023
@1t5j0y 1t5j0y moved this from In QA to QA Ready in Avni Product Nov 6, 2023
@himeshr himeshr moved this from QA Ready to In QA in Avni Product Nov 6, 2023
@himeshr
Copy link
Contributor

himeshr commented Nov 6, 2023

Test Details


The approaches tried to create additional individuals with "null" lowestAddressLevels where as follows:

  1. Update server to set the addressLevel as null
-- //Allow empty location
select * from individual where uuid = '212c4e48-3060-403c-91a2-63690d98cdd4'; --335080
update individual set address_id = null, last_modified_date_time = now() where uuid = '212c4e48-3060-403c-91a2-63690d98cdd4';
  1. Use playground to manually update an Individual to set the addressLevel as null
async function executeIndividualAddressVoidQuery(type, setOutput) {
    //waitForNotNULL(getDb)
    console.log("executeIndividualAddressVoidQuery");
    setOutput("Preparing db");
    let db = await RealmFactory.createRealm()
    if(db == null) {
        return -1000;
    }
    try {
        if (db.objects(Individual.schema.name).filtered('uuid = $0', '212c4e48-3060-403c-91a2-63690d98cdd4').length > 0) {
            console.log("Clearing Lowest Address Level for Individual with uuid \'212c4e48-3060-403c-91a2-63690d98cdd4\'");
            let individual = db.objects(Individual.schema.name).filtered('uuid = $0', '212c4e48-3060-403c-91a2-63690d98cdd4')[0];
            console.log("individual.lowestAddressLevel", individual.lowestAddressLevel);
            let clonedIndividual = individual.cloneForEdit();
            clonedIndividual.lowestAddressLevel = null;
            db.write(() => {
                db.create(Individual.schema.name, clonedIndividual, true);
            })
            console.log("clonedIndividual.lowestAddressLevel", clonedIndividual.lowestAddressLevel);
        }
        return 0;
    } catch (e) {
        console.error(e);
        return setOutput(-1);
    }
}

Above scenarios failed due to

  1. the inability to save or update Individuals with lowestAddressLevel as null in the client, due to checks in place and additional syncCriteria mismatch (null address are ignored, if not for direct-assignment)
  2. the inability to sync Individuals with lowestAddressLevel as null in the server to the client (Models has mandatory constraint for the field and there are several validations that disallow nulls there)

Because of these, we are forced to test this by use of FastSync replace, which can only help test already existing data anamolies and not create new ones.

@himeshr himeshr moved this from In QA to Done in Avni Product Nov 6, 2023
@himeshr himeshr moved this from Done to In QA in Avni Product Nov 7, 2023
@vinayvenu vinayvenu reopened this Nov 7, 2023
@github-project-automation github-project-automation bot moved this from In QA to Triaged in Avni Product Nov 7, 2023
@himeshr himeshr moved this from Triaged to In Progress in Avni Product Nov 7, 2023
himeshr added a commit to avniproject/avni-models that referenced this issue Nov 7, 2023
…undefined" error after running migration 180
@himeshr
Copy link
Contributor

himeshr commented Nov 7, 2023

In-order to Validate this better, modified the filter criteria for migration180, to be all individuals, irrespective of whether the addressLevel is null or not.
With this change, tested dumpRestore for following organisations:

  • apf odisha
  • gvamp uat
  • rwb 2023

This helped validate various type of deletions involved in the migration180, such as

  • encounters
  • programEnrolments
  • programEncounters
  • checklists
  • entityApprovalStatus
  • Individuals, etc..

himeshr added a commit that referenced this issue Nov 7, 2023
@himeshr himeshr moved this from In Progress to Done in Avni Product Nov 7, 2023
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

5 participants