IBM / lmctl

Cloud Pak for Network Automation (CP4NA) (previously ALM/TNCO) command line tool
Apache License 2.0
4 stars 19 forks source link

Support pydantic 1.10.x+ #158

Open dvaccarosenna opened 1 year ago

dvaccarosenna commented 1 year ago

Is your feature request related to a problem? Please describe. As explained in #156 there are incompatibilities between dcutils of lmctl and Pydantic 1.1.0. The issue can be shown by installing Pydantic 1.10.x and running python3 -m unittest tests.unit.utils.dcutils.test_dc_capture.TestRecordAttrs.test_record_pydantic_dataclass from lmctl. The test will fail.

It seems like the __init__ function of Pydantic dataclasses has changed so the _wrap_init method of lmctl.utils.dcutils.dc_capture can no longer infer the arguments of the constructor. The below snippet from _wrap_init is the root of the problem. The value of expected_args is [] when it previously returned the argument specs in the constructor, in order of definition:

init_arg_spec = inspect.getfullargspec(existing_init)
expected_args = init_arg_spec.args

Describe the solution you'd like For lmctl to work with Pydantic 1.10.x, ideally without losing the functionality of dcutils. Alternatively, we'll have to replace usage of dcutils, which is used to guide the attributes to be included when deserializing a dataclass into YAML/JSON. This is particularly useful when rewriting the lmctl config file as it avoids writing attributes that have defaults but were never set by the user.