HTBox / MobileKidsIdApp

Application for enabling storage and retrieval of important information on missing children.
Apache License 2.0
46 stars 44 forks source link

Child list doesn't display after selecting child photo #332

Open rockfordlhotka opened 5 years ago

rockfordlhotka commented 5 years ago

After adding a photo to a child that is not the first child in the child list, back out to the child list and it is blank (on iOS at least).

Exit to main menu, go back to child list and the children are listed.

brunck commented 5 years ago

It seems that after doing this for any child that isn't the first, when navigating back it may lose just the 2nd one in the list, which may or may not be the one selected and had the photo added to.

brunck commented 5 years ago

The problem seems to appear after this line.

For a Childprofilelist of n items in Model, after this line Model has n-1 items and is missing the 2nd item that was in that list.

brunck commented 5 years ago

This is still happening on both iOS and Android.

left-on-red commented 5 years ago

same visual bug reproducible by deleting a child list item. child 2 gets visually removed but fixes itself by exiting to main menu and returning to children list. not strictly an issue with images

brunck commented 5 years ago

I think we'd see more than just the 2nd in the list go missing if the Child list was longer when we take an action that repros this (adding a photo to one of the Child entities, etc.)

brunck commented 5 years ago

What seems to be happening here is a bit complex. It's reproduced in the unit test as part of PR #357 . It only shows up if you have 3 or more Child entities in the Family. Let's say we have 4 for example. We see this easily if we add an entity like a Photo to one of the Child entities. We're seeing this in other situations but we'll use a Photo add for this example. All this is the same as what the unit test does. I don't know at the moment why this isn't reproduced when an entity isn't added to one of the Child entities in the list, so we make sure to do that.

After adding the photo and navigating back to the previous page, ChildProfileList.SaveFamilyAsync() is invoked. This does a couple of key things in this case: ISavable.SaveAsync() and shortly after, GraphMerger.MergeBusinessListGraph() are invoked.

Model has 4 Child entities with the IBusinessObject.Identity (implemented in BusinessBase in this case) with values of 1, 2, 3 and 4. Those existed before the SaveAsync() call. saved now contains 4 nearly identical Child entities with identities of 5, 6, 7 and 8. I don't know at this point whether this is proper/expected or not.

MergeBusinessListGraph() then gets invoked with Model as "target" and saved as "source." In this method, the key part is a loop over each item in source, comparing each item with all the items in target. If the source item's identity does not match any of the items in target, target has that source item added to it. The target list now has 5 Child entities with identities of 1, 2, 3, 4 and 5. Something important happens as part of this Add operation though: The identity of the last item is incremented to 6. So once you get to the next iteration of the loop, the entities in the list have identities of 1, 2, 3, 4, and 6. The loop continues to the next item in source which has an identity of 6. The following check sees that target does have an item with an identity of 6, so the Add operation is skipped and we move to the next iteration in the loop.

Ultimately (without going into more detail about the rest of the graph merge method) we end up with a Model that has only 3 Child entities, with the 2nd one left out. I think it may have something to do with one of these Child entities having a Parent but I'm not sure at the moment.