ygot
ygot copied to clipboard
Unable to lookup list element node with key type int64
Using ytypes.GetNode to lookup a list element node where the key type is int64 fails with the error:
"could not get path keys at elem:<path elems>: cannot convert type int64 to a string for use in a key:<int64 val>"
It looks like GetNode ends up calling ygot.KeyValueAsStringat some point, and this function is missing an entry for int64 when converting to string, https://github.com/openconfig/ygot/blob/master/ygot/render.go#L718
Is this just a typo? The following change resolves the issue for me
diff --git a/ygot/render.go b/ygot/render.go
index e44f621..593d0a2 100644
--- a/ygot/render.go
+++ b/ygot/render.go
@@ -715,7 +715,7 @@ func KeyValueAsString(v any) (string, error) {
}
switch kv.Kind() {
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
return fmt.Sprintf("%d", v), nil
case reflect.Float64:
return fmt.Sprintf("%g", v), nil
Yes, this looks like an error -- I'm happy to review a PR to cover this, or I can make a change (although it might take a short while).