ocket8888 commented on code in PR #7099:
URL: https://github.com/apache/trafficcontrol/pull/7099#discussion_r1005062709
##########
traffic_ops/v5-client/deliveryservice_requests.go:
##########
@@ -58,31 +58,31 @@ func (to *Session) CreateDeliveryServiceRequest(dsr
tc.DeliveryServiceRequestV4,
dsr.AuthorID = res.Response[0].ID
}
- var ds *tc.DeliveryServiceV4
+ var ds *tc.DeliveryServiceV5
if dsr.ChangeType == tc.DSRChangeTypeDelete {
ds = dsr.Original
} else {
ds = dsr.Requested
}
- if ds.TypeID == nil && ds.Type.String() != "" {
+ if ds.TypeID <= 0 && ds.Type != nil && *ds.Type != "" {
Review Comment:
The Type is known to humans by its name, so this block was meant to populate
the ID if it wasn't given by using the Type's Name (if that *is* given,
otherwise it's an error). Because `ds.Type` is a pointer, it can be `nil`, so
its value must not be accessed in that case, or a bad error response will be
returned to the user. You also can't look up a Type with a blank Name, because
Type Names can't be blank. The old code called `.String()`, which would
segfault if the `ds.Type` reference was `nil`, so I added the `nil` check to
avoid that. `TypeID` is no longer a pointer, so instead of `nil` I checked for
the "zero" value of the property's datatype (and also invalid values i.e.
negative ones).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]