-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
helper/schema: Exists API #766
Conversation
+1 |
What of the case where implementing |
@mitchellh with this choice the documentation will no more reflects the code. This must not be. I would suggest the following :
(that's a conceptual comment as I didn't even deep look at that feature. Hope this still make sense) |
@bitglue Good point, in this case there will be two round trips. I'm not sure if there is a better way around this, since I think having 1 round trip but forgetting to handle this case is more annoying. @frntn Sorry I don't understand. It is only optional for backwards compatibility reasons. The "code" will show its optional, but its not truly meant to be. The documentation reflects the real state: it is required. It happens to work without specifying it, but the documentation says that it is required, so you do this at your own peril. |
My concern was about the contradiction between "The 'code' will show its optional" vs "The documentation reflects the real state: it is required". I am still not ok with that, but thanks to your last sentence I understand now what you mean. It makes sense. Thanks. |
@mitchellh I agree: I've already encountered this bug on a couple resources, and made the same mistake in my first provider implementation. However, the current mechanism of Another approach would be making object existence explicit in some other way which isn't a separate function. For example, |
@frntn I think the solution would be to put in the code (via a comment above the field) that it is required. So even if the logic shows its optional, the docs both on the site and in the code show its not. @bitglue Your latter two ideas are not bad. I'll sit on that one. I don't think its too late to undo Exists, so let me think about it. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This adds
Exists
to thehelper/schema.Resource
. This is called prior toRead
and handles the situation that a resource no longer exists.I added this as a formal CRUD-like operation because we get so many bugs where
Read
isn't handling the case where a resource doesn't exist properly. By documenting this case and exposing it as a first-class callback, I hope that resources in the future will be of high quality.For backwards compatibility, this is an optional field, but we don't document it as such in the website since we want to encourage its use.
/cc @pearkes