getodk / collect

ODK Collect is an Android app for filling out forms. It's been used to collect billions of data points in challenging environments around the world. Contribute and make the world a better place! ✨📋✨
https://docs.getodk.org/collect-intro
Other
715 stars 1.37k forks source link

Entities from finalized registration and update forms after resetting "saved forms and entities" #6435

Open dbemke opened 3 days ago

dbemke commented 3 days ago

ODK Collect version

the master version ce00913a7cd87d3f5b2472e834ac6a9974d1906c

Android version

10, 14

Device used

Redmi 9T, Pixel 7a

Problem description

I’m not sure what should happen with entities from finalized registration and update forms after resetting "saved forms and entities" in Collect setting. After resetting saved forms there aren’t any entities/rows in the db files. Afterwards, if a user finalizes an update to an entity (in the update form), the finalized entity doesn’t appear on the list in the update form (I guess it isn’t created locally/offline – no new rows in db files). If a user finalizes the registration form, in the update form other entities are removed form the list and there’s only the new entity (registration form creates a row in db files). So there are 2 different scenarios what appears in the update form depending on what a user finalizes after resetting saved forms. I guess it means that after resetting saved forms local entities are enabled again only after refreshing the list of blank forms (or downloading them manually). Is it ok for the time being or finalizing an entity form should trigger local entities (after resetting) ?

Steps to reproduce the problem

  1. Download a project with entities registration form, follow-up form and update form with some existing entities (e.g. trees registration, follow- up, update with the new entity spec user "one" in https://staging.getodk.cloud/#/projects/101/app-users).
  2. Go to Settings- Project management- Reset, select "Saved forms and entities” and tap "Reset”.
  3. Go to Settings- Form management- Auto send and set "off”.
  4. Go to the update form, select an entity an finalize the form.
  5. Go to the update form and check with version of the entity updated in step 4 is on the list (there is the version without the update + other entities are on the list).
  6. Go to the registration form and create an entity.
  7. Go to the update form and check which entities are on the list (there’s only the new entity, other entities aren’t on the list).
lognaturel commented 2 days ago

This is not a good state to be in!

Here's what I would expect "saved forms and entities" to do:

This would honor the intent of that reset action which is to remove user/locally-created content but keep server/form-level content.

I'm realizing this may be tricky to do currently: I don't know whether there's an easy way to identify those source CSVs at that point in time since they are stored at the form level. If it's a big lift, I think we should consider removing the ability to clear out filled forms and entities for this first version.

This issue is also related to https://github.com/getodk/collect/issues/6425 and to the fact that when multiple forms use the same Entity List we currently download it multiple times. All of these have to do with how the system identifies what is an Entity List vs a static CSV attachment.

grzesiek2010 commented 1 day ago

We store the state of entities in the database, marking them as either online or offline. Can’t we just remove the offline ones when resetting saved forms? As I understand it, the result would be the same as deleting all entities from the database and rebuilding it using the CSVs originally downloaded from the server but it's simpler.

lognaturel commented 1 day ago

I believe we only know whether the Entity has any change that was made offline. For example, if you get an Entity from the server and update it locally, it is marked as offline. We don’t keep the original Entity value in the database currently, we mutate it in place.

grzesiek2010 commented 19 hours ago

Right, how about creating a copy of the tables containing entity data each time we save entities from the server? Then, during resetting, we could restore the last saved state. This would take some extra time during downloading entities and increase the size of the database but it could be the easiest solution.