ygot icon indicating copy to clipboard operation
ygot copied to clipboard

Generator: Deviations are not considered when performing leaf ref lookup.

Open soltas-g opened this issue 11 months ago • 1 comments

When not-supported deviations are used on intermediate nodes, leaf ref lookups on child nodes fail with error: ERROR Generating GoStruct Code: could not resolve leafref path: [ <path> ]

This seems to be occurring in the following code section:

	e := t.GetLeafValue(fixedPath)
	if e == nil {
		return nil, fmt.Errorf("could not resolve leafref path: %v from %v, tree: %v", fixedPath, contextEntry, t)
	}

https://github.com/openconfig/ygot/blob/2dd1852623dd2adaa5d83d3fa780ebd72f5c04e2/yangschema/yangschema.go#L85


Deviations should be considered when performing leaf ref lookup or returning nil should not be a failure case (potentially toggle-able by flag)


Reproduction:

instance.yang

module test-instance {

  yang-version "1";

  // namespace
  namespace "instance";

  prefix "t-inst";

  grouping instance-top {
    description
      "Top-level grouping containing a list of instances.";

    container instances {
      description
        "instances";

      list instance {
        key "name";

        description
          "instances configured on the local system";

        leaf name {
          type leafref {
            path "../config/name";
          }
          description
            "A unique name identifying the instance";
        }

        container config {
          description
            "Configuration parameters relating to an
            instance";
          uses instance-config;
        }
      }
    }
  }
  grouping instance-config {
    description
      "Configuration parameters relating to a top-level
      instance";

    leaf name {
      type string;
      description
        "name for the instance.";
    }
  }
  uses instance-top;
}

test-deviations.yang

module test-deviations {

  namespace "instance-deviations";

  prefix "test-devs";

  import test-instance { prefix t-inst; }

  organization "test";

  deviation /t-inst:instances/t-inst:instance/t-inst:config {
    deviate "not-supported"; 
  }
}

ygot generator run with

-compress_paths=false -output_dir=~ -package_name=pkg -ignore_circdeps -ignore_unsupported=true -exclude_modules=ietf-interfaces  
 -generate_fakeroot -fakeroot_name=device -generate_simple_unions -generate_append -generate_getters -generate_rename -structs_split_files_count=5 -ygot_path=<> -ytypes_path=<> -goyang_path=<>  -path=test third_party/openconfig/vendor/cisco/yang/test/instance.yang third_party/openconfig/vendor/cisco/yang/test/test-deviations.yang

soltas-g avatar Mar 26 '25 19:03 soltas-g

I don't think this is valid -- if you deviate not-supported the target of a leafref, then the leaf that references it isn't valid any more (it can never have any valid values). In this case, the instance list can never have a key, which cannot be valid.

What's the use case for supporting this please?

robshakir avatar May 31 '25 02:05 robshakir