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

Resource not recreated if not found with read_search #269

Open
mauriceackel opened this issue May 16, 2024 · 0 comments
Open

Resource not recreated if not found with read_search #269

mauriceackel opened this issue May 16, 2024 · 0 comments

Comments

@mauriceackel
Copy link

When a resource state is refreshed, the provider tries to read the resource from the API.

If the read fails with a 404, we set obj.id = "" causing a recreation of the resource. This works in the following cases:

  1. The read requests returns a 404
  2. The read request returns a 200 but there was read_search properties provided and there was an error while searching the resource in the results (e.g. unknown results_key, unknown search_key, etc.)

However, when the resource was not found with read_search, the resource is not marked for creation!

Expected behaviour: If the resource was not found during state refresh (either because the API returned a 404 or the search did not return a result), the resource should be marked for creation.

Investigation

The issue is that when the object is read in this line, we use the findObject method and check, whether it returns an error. The error is returned in many cases but it is not returned, if the object exists in the state but was not found using in the findObject method. This behaviour can be seen in this line. There, we only return an error if the object id was "", but not if it existed before.

I'm not sure where the best place to fix this issue is without breaking existing functionality. I'd assume that the best place to check would be in the readObject method. Here, we could extend the check to not only set obj.id = "" if there was an error, but also if objFound is undefined.

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

1 participant