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

Can't reschedule Daily Task #655

Open
williamkey123 opened this issue Apr 23, 2022 · 2 comments
Open

Can't reschedule Daily Task #655

williamkey123 opened this issue Apr 23, 2022 · 2 comments

Comments

@williamkey123
Copy link

I have a task for a user to take a pill every day at a time of their choosing. I want to give them the ability to reschedule it, and tried two different things, but the both seem to be creating problems.

First, I tried updating the task's schedule to set the existing OCKScheduleElement to have an end date of today, and add a new OCKScheduleElement that starts tomorrow with the new time the user has chosen. This resulted in the following error:

Failed to update: Updating task 2FF575D7-E4FD-4C51-A5D0-CED6126E9826 failed. The new version of the task takes effect on 2022-03-24 16:00:00 +0000, but an outcome for a previous version of the task exists on 2022-04-22 16:00:00 +0000. To prevent implicit data loss, you must explicitly delete all outcomes that exist after the new version's effectiveDate before applying the update, or move the new version's effectiveDate to some date past the latest outcome's date. [emphasis mine]

Okay great, and thanks CareKit team for providing a really descriptive error with potential solutions! So next, I tried the latter solution since that seems sensible in my case - I updated the existing task with the new schedule, and set the effectiveDate to tomorrow.

That solution allowed me to save the changes, but there were two problems. One is that the Daily Care view stopped showing previous days as checked, even though I could go to those days and see that the task had been completed. The second is that I now had two tasks in the store with the same ID, so if I tried to delete or modify them further, I got an error:

Invalid value: Identifiers contains duplicate values!

Is this a bug, or am I just not doing this correctly? Should I be assigning the task a new ID when I edit it, so it doesn't conflict with the previous one? Should I just be creating a new task entirely and setting an end date on the old one?

@gavirawson-apple
Copy link
Collaborator

Sounds like you're doing all the wright things here! Let me ask a few questions to better understand where the issue might be.

One is that the Daily Care view stopped showing previous days as checked, even though I could go to those days and see that the task had been completed.

Where in the feed is task completion working properly, and where is it not showing up? Are the task cards showing completion correctly, but the rings up top are not?

Invalid value: Identifiers contains duplicate values!

Attaching the code that copies and updates the task in the store will be helpful here if you're okay sharing. But my guess is that CareKitStore mistakenly can't find the previous version of the task and decides to save it as a new one rather than update it. Try adding some breaking points through the code path that saves the task to see if it takes the "save" or "update" path.

@zhang-bo-lilly
Copy link

@gavirawson-apple, I think I am experiencing a similar problem here. I have created a toy example updateTaskSchedule that can reproduce the problem quite consistently as shown in the recording below.

Simulator.Screen.Recording.-.iPhone.12.Pro.Max.-.2022-09-09.at.17.30.30.mp4

In the test, I created a task for a user to take a daily pill anytime during the day for two days. After that, on day 3, I update the schedule for this task such that from day 4, the user will start to take the pill every other day. When I update the schedule, I set the effectiveDate to be on day 4 so the existing outcomes remain. As shown in the video, there is no error in updating the schedule, the card shows up in the future, and I can also go back to the previous days. However, the program will crash the moment I sweep the calendar to a new week. The corresponding screenshot of Xcode is

Screen Shot 2022-09-09 at 5 34 39 PM

It would be great if you can take a look on this. I am not sure if there is something wrong with my code. Thanks.

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

No branches or pull requests

3 participants