Skip to content

Conversation

@ramichael77
Copy link

@ramichael77 ramichael77 commented Aug 29, 2025

The fix is for proper leaflist parsing and processing.
The 0.8.15 does not have leaflist support.
I failed to use leaflist from main in my project and was forced to fix it.

@akarneliuk
Copy link
Owner

Is there any testing you can share @ramichael77 ? what is the data you were not able receive and you are able now? also, what about compatibility with previous way?

@ramichael77
Copy link
Author

Hi,
Thanks for reviewing!
The val_leaflist support was added in https://github.com/akarneliuk/pygnmi/pull/162/files and was not published in 0.8.15

I tried to use not published https://github.com/akarneliuk/pygnmi/blob/master/pygnmi/client.py#L593C40-L599C100 but immediately failed as the code has the following issue.

  1. Problem: Any subitem under leaflist_val is parsed as "json_val" as the hasattr(...) for gRPC is always True:

                                         for e in val_leaflist.leaflist_val.element:
                                             if hasattr(e, "json_val"):        ########## hasattr for gRPC is always True
                                                 element_val.update(json.loads(e.json_val))
                                             elif hasattr(e, "json_ietf_val"):   ##########   hasattr for gRPC is always True
                                                 element_val.update(json.loads(e.json_ietf_val))
    

The proposed code uses e.HasField(...) and e.ListFields() that are provided by python grpcio grpcio-tools

The all other code uses HasField(...) but not hasattr(...). see for example code below:

# https://github.com/akarneliuk/pygnmi/blob/ccf168a5a80e3611d572cc7bac00ba8600aed47e/pygnmi/client.py#L558
                                    elif update_msg.val.HasField("json_val"):
                                        update_container.update(
                                            {"val": process_potentially_json_value(update_msg.val.json_val)}
                                        )

There is a part of message that I got from our server and the message was parsed by gnmic but not pygnmi:

update {
    path {
      elem {
        ...............  # path was removed 
      }
    }
    val {
      leaflist_val {
        element {
          uint_val: 1434098893918572563
        }
        element {
          uint_val: 13193780073102540425
        }
        element {
          uint_val: 4404749674496952716
        }
        element {
          uint_val: 6951842183180090997
        }
        element {
          uint_val: 4016627188829016379
        }
.............
  1. what about compatibility with previous way?
    The previous code was able to parse the "json_val" ONLY as I mentioned above.
    My code permits the "json_val" parsing as well:
                                                if e.HasField("json_val"):
                                                    element_val.append(json.loads(e.json_val))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants