-
Notifications
You must be signed in to change notification settings - Fork 597
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
fix!: allow clearing comments from the Go API #1166
Conversation
Oops! It looks like no changelog entry is attached to this PR. Please include a release note as described in https://github.com/cloudflare/cloudflare-go/blob/master/docs/changelog-process.md. Example:
If you do not require a release note to be included, please add the |
Codecov Report
@@ Coverage Diff @@
## master #1166 +/- ##
==========================================
- Coverage 49.40% 49.26% -0.15%
==========================================
Files 127 128 +1
Lines 12290 12434 +144
==========================================
+ Hits 6072 6125 +53
- Misses 4840 4905 +65
- Partials 1378 1404 +26
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
I like the approach of using pointers for two reasons. The first is that it gives us the states we need (no comment aka uninitialised, empty comment and a stringy value). The second is that in a future iteration of the SDK we will be moving all fields in struct to be pointers to account for the first point where we need to differentiate between uninitialised values and zero values (which has bit us a couple of times). This will keep us working towards that path. I don't think we need a custom type here and in fact, it may make end use harder since we already have |
@jacobbednarz I will update this PR, but I would like to understand the following comment better:
I am happy to be proved wrong but I do not see how
I believe for |
I'll have to check when I'm in front of a computer with this open next. I was sure we've done this elsewhere (likely for edge rules engine) but I'll need to have a dig around. |
aaf2c48
to
f2c7416
Compare
Currently, empty DNS record comments will be understood as "unset" or "unspecified", making it impossible to clear a comment. This commit fixes that. This is a breaking change, but since comments were introduced only in 0.58.0, chances are almost no applications depend on them yet.
f2c7416
to
321392d
Compare
i think the bit that is tripping you up here is the if the team want to support three states (null/nil, empty and strings) then that needs to possible and we leave out the |
@jacobbednarz Thanks, but I am still not convinced by the
None of these choices can keep the existing comment of a record. I think this is worse than not being able to clear comments (the current status). |
i'm also curious how much of an issue this really is (setting the value to an empty string). what would the use case be to set it back to |
@jacobbednarz It's either |
taking a further step back here, is this enough of a pattern that we should we swap to a 3rd party JSON package that supports the given the benchmarks, I'm tempted to make the swap irrespective of whether we end up using the |
@jacobbednarz The library looks interesting. |
another option, in https://github.com/cloudflare/cloudflare-go/blob/master/dns.go#L236, we already fetch the existing record for a couple of conditions so we can potentially extend this for a scenario where we haven't provided an explicit
thoughts? |
A record lookup would work, but it is perhaps "inelegant" and the benefits of avoiding custom marshalers are shrinking. I have two objections:
|
i'm going to close this off and take it internally with the team. we avoid custom unmarshal/marshal logic where possible since it makes debugging issues increasingly difficult when it is included in another struct so adding this change would be behind updating the public API in my books. the DNS team or myself will provide a PR if/when we need to adjust anything here after we reassess the API and it's integrations in the coming week or so. thanks for the PR and discussion so far @favonia! |
circling back on this issue via #1194 now that the API allows empty comments to clear it. |
Updates the SDK to allow sending empty strings to the API to clear DNS comment values. Fixes cloudflare#1166
This functionality has been released in v0.60.0. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
Description
Currently, empty DNS record comments will be understood as "unset" or "unspecified", making it impossible to clear the comment of an existing record. This PR fixes that. This is a breaking change, but since comments were introduced only in 0.58.0, chances are almost no applications depend on them yet. Technically, a new type
DNSRecordComment
was introduced to facilitate the correct marshaling of empty comments. See #1158 for further discussions of the current API behavior.The field
Comment
inDNSRecord
andCreateDNSRecordParam
is of typeDNSRecordComment
so that the zero value means "empty comment". However, the fieldcomment
inUpdateDNSRecordParam
andListDNSRecordsParam
is of type*DNSRecordComment
(notice the star) so that the zero value means "not filtering / not changing".One possible design choice is to make the field
Comment
ofCreateDNSRecordParam
of type*DNSRecordComment
so that the zero value means "not specifying the comment", potentially matching the current behavior and also the design ofProxied
field better (which is of type*bool
instead ofbool
). I honestly do not know which one is better. Theoretically, we can and probably should change the type of the fieldProxied
in bothDNSRecord
andCreateDNSRecordParam
tobool
, but that will be out of the scope of this PR.Tagging @janik-cloudflare.
This PR is incomplete. It still needs more test cases and entries for the Changelog.
Has your change been tested?
Barely, but it is tested at the same level of existing code about record comments. The official API documentation does not specify the expected behavior of the API for empty comments, either. I prefer waiting for people working at Cloudflare to add the test cases that they think are correct. I have manually tested the
UpdateDNSRecord
against the real Cloudflare server and it seemed to match what I expected.Types of changes
What sort of change does your code introduce/modify?
Checklist: