Skip to content

test: Error when saving outcomes related to multiple tasks #725

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cbaker6
Copy link
Contributor

@cbaker6 cbaker6 commented May 1, 2025

Fixes a bug when attempting to save multiple outcomes that are related to different taskUUID's. In the case of this type of save, an error is thrown since there's a verification of the taskUUIDs already being in the store.

This seems to be fixed in #727, but the test case in this PR is slightly more specific on testing the issue, let me know if you want me to close the PR.

fetchObjects is called here:

let taskUUIDs = outcomes.map { $0.taskUUID }
let tasks: [OCKCDTask] = try context.fetchObjects(withUUIDs: taskUUIDs)

and the error happens here:

let taskUUID = outcome.taskUUID
let task = tasksGroupedByUUID[taskUUID]?.first
guard let task else {
let msg = "Failed to find task with UUID \(taskUUID)"
throw OCKStoreError.invalidValue(reason: msg)
}

The grouping of taskID's handles the issue of multiple tasks being fetched.

This method looks like it's only being used by OCKOutcome, all others only require a fetch of one object, so they use fetchObject instead of fetchObjects.

The workaround is the developer will need to group OCKOutcome's by taskUUID and then manually save each group instead of trying to save all at once.

You can verify by running the unit test I added against the code before the commit.

@cbaker6 cbaker6 changed the title fix: Error when saving outcomes related to multiple tasks test: Error when saving outcomes related to multiple tasks May 15, 2025
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.

1 participant