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

Using activeSurveyFlow to make flow async #2890

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

anandwana001
Copy link
Collaborator

Copy link

codecov bot commented Dec 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.55%. Comparing base (9ef90ad) to head (c351daa).
Report is 6 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2890      +/-   ##
============================================
+ Coverage     62.52%   62.55%   +0.02%     
  Complexity     1203     1203              
============================================
  Files           267      267              
  Lines          6357     6358       +1     
  Branches        881      880       -1     
============================================
+ Hits           3975     3977       +2     
  Misses         1831     1831              
+ Partials        551      550       -1     
Files with missing lines Coverage Δ
...round/ui/datacollection/DataCollectionViewModel.kt 73.23% <100.00%> (+0.64%) ⬆️

... and 1 file with indirect coverage changes

@shobhitagarwal1612
Copy link
Member

shobhitagarwal1612 commented Dec 1, 2024

Won't this change now start failing to get the job as null?

@anandwana001
Copy link
Collaborator Author

Won't this change now start failing to get the job as survey is null?

Should we make the job as a flow too?

@shobhitagarwal1612
Copy link
Member

The question remains the same, will that pass on the error to the next item or will it stabilize the screen when survey is null?

@anandwana001
Copy link
Collaborator Author

The question remains the same, will that pass on the error to the next item or will it stabilize the screen when survey is null?

as the data collection screen is completely dependent on the activeSurvey, so in the worst case should we navigateUp or should we show some loading retry to fix the state flows and get the updated data?

@shobhitagarwal1612
Copy link
Member

should we show some loading retry to fix the state flows and get the updated data?

We shouldn't navigate up unless it's the last resort. Given that we know the survey id, we should try to make our sync code async and wait until it is ready.

Comment on lines +103 to +105
private val activeSurvey: Survey = runBlocking {
surveyRepository.activeSurveyFlow.filterNotNull().first()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if the coroutine is never completed? Will the app freeze until ANR error occurs?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During the standup today, @anandwana001 suggested adding a timeout here. @gino-m I suggested that we allow the timeout exception to propagate and crash the app, since not being able to load the survey from the local db would be an unrecoverable error.

Ideally, we would ensure the survey was active before rendering the DataCollectionFragment. We could then use SurveyRepository.activeSurvey directly rather than the Flow to get the current survey. @shobhitagarwal1612 Is this possible, based on how the fragment gets activated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we would ensure the survey was active before rendering the DataCollectionFragment. We could then use SurveyRepository.activeSurvey directly rather than the Flow to get the current survey. @shobhitagarwal1612 Is this possible, based on how the fragment gets activated?

I don't think so, the fragment gets restored when the activity is started and the injected dependencies are initialized after the fragment is created.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, the fragment gets restored when the activity is started and the injected dependencies are initialized after the fragment is created.

On configuration change, yes, but on app restart we explicitly redirect to this fragment if there's an unsaved draft, no? On configuration change the VM should still exist, so this wouldn't be an issue. In HomeScreenFragment.onViewCreated, however, we navigate to the data collection screen if there's an unsaved draft.

That said, I agree it would be more robust for the fragment which needs the survey to handle the edge cases, rather than the navigation source.

@anandwana001 Let's keep the fix in this PR plus timeout as a workaround, we can add other handle delayed load and other edge cases if it turns out to be an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[App Crash] activeSurvey is null
4 participants