cloudflare / cloudflare/cloudflare-go
RecordService ListAutoPaging iterator's AsUnion returns wrong types in 7.8.0
- Dominant language
- Go
- Stars
- 2.1k
- Forks
- 781
- Avg merge
- 12h 38m
- Merged PRs (30d)
- 4
Description
### Confirm this is a Go library issue and not an underlying Cloudflare API issue
- [x] This is an issue with the Go library
### Describe the bug
I noticed since upgrading to 7.8.0 that the `RecordResponseAAAARecord` case (see below) never gets called (also the changelog never indicated that this service's union types added the `Record` suffix which is a breaking change).
Debugging, I can confirm it just simply is using the wrong type. It's marking AAAA and CNAME (at least, I have not tried other record types) as A records:
```
dns.RecordResponseARecord {ID: "REDACTED", CreatedOn: time.Time(2026-08-01T12:26:19Z){wall: 851455000, ext: 63921183979, loc: *time.Location nil}, Meta: dns.RecordResponseARecordMeta {DeadGlue: false, IsGlue: false, ShadowedBy: []string len: 0, cap: 0, nil, ShadowedRecordsCount: 0, JSON: (*"dns.recordResponseARecordMetaJSON")(0xd9791a2ec58)}, ModifiedOn: time.Time(2026-08-01T12:30:20Z){wall: 774005000, ext: 63921184220, loc: *time.Location nil}, Proxiable: true, CommentModifiedOn: time.Time(0001-01-01T00:00:00Z){wall: 0, ext: 0, loc: *time.Location nil}, TagsModifiedOn: time.Time(0001-01-01T00:00:00Z){wall: 0, ext: 0, loc: *time.Location nil}, JSON: dns.recordResponseARecordJSON {ID: (*"apijson.Field")(0xd9791a2ed20), CreatedOn: (*"apijson.Field")(0xd9791a2ed38), Meta: (*"apijson.Field")(0xd9791a2ed50), ModifiedOn: (*"apijson.Field")(0xd9791a2ed68), Proxiable: (*"apijson.Field")(0xd9791a2ed80), CommentModifiedOn: (*"apijson.Field")(0xd9791a2ed98), TagsModifiedOn: (*"apijson.Field")(0xd9791a2edb0), raw: "{\"id\":\"REDACTED\",\"name\":\"REDACTED\",\"type\":\"AAAA\",\"content\":\"1234:1234:1234:1234:1234:1234:1234:1234\",\"proxiable\":true,\"proxied\":true,\"ttl\":1,\"settings\":{},\"meta\":{},\"comment\":null,\"tags\":[],\"created_on\":\"2026-08-01T12:26:19.851455Z\",\"modified_on\":\"2026-08-01T12:30:20.774005Z\"}", ExtraFields: map[string]apijson.Field [...]}, ARecord: dns.ARecord {Name: "REDACTED", TTL: 1, Type: "AAAA", Comment: "", Content: "1234:1234:1234:1234:1234:1234:1234:1234", PrivateRouting: false, Proxied: true, Settings: (*"dns.ARecordSettings")(0xd9791a2ee30), Tags: []string len: 0, cap: 0, [], JSON: (*"dns.aRecordJSON")(0xd9791a2ee98)}}
```
I have redacted the record name and the real IPv6 address, but you can clearly see the raw type is AAAA, but the type I get for `record` is `RecordResponseARecord`.
### To Reproduce
See code below.
### Code snippets
```Go
dnsService := client.DNS
recordsService := dnsService.Records
recordsIterator := recordsService.ListAutoPaging(
context.TODO(),
dns.RecordListParams{
ZoneID: cloudflare.String(zoneId),
},
)
for recordsIterator.Next() {
recordResponse := recordsIterator.Current()
record := recordResponse.AsUnion()
switch source := record.(type) {
case dns.RecordResponseAAAARecord:
// never gets called despite there clearly being AAAA records in my zone
case dns.RecordResponseCNAMERecord:
// also never gets called, the same behavior...it's just seeing CNAME records as A records
}
}
```
### OS
Fedora Linux 44
### Go version
Go 1.26.5
### Library version
github.com/cloudflare/cloudflare-go/v7 v7.8.0
Contributor guide
Research direction
Start with the RecordService.Records ListAutoPaging entry point and the recordResponse.AsUnion() call shown in the reproduction, then run the supplied iterator and type-switch example against AAAA and CNAME records. Done means AsUnion returns the corresponding RecordResponseAAAARecord and RecordResponseCNAMERecord types rather than treating them as A records.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 64/100