elrond-sdk-erdpy icon indicating copy to clipboard operation
elrond-sdk-erdpy copied to clipboard

staking-provider commands not working (AttributeError). Incomplete migration to pathlib.

Open ashpool37 opened this issue 3 years ago • 1 comments

Some subcommands under staking-provider, for instance, erdpy staking-provider add-nodes, raise an AttributeError when trying to parse a PEM file.

Versions affected

Version 1.0.23 from PyPi.

Steps to reproduce

Issue the add-nodes command to add some nodes to a staking pool. Some irrelevant arguments were omitted.

erdpy staking-provider add-nodes --validators-file "$PWD/validators.json" --using-delegation-manager ...

validators.json:

{
	"validators": [
		{ "pemFile": "validator1.pem" },
		{ "pemFile": "validator2.pem" }
	]
}

Expected behaviour

A transaction is put together and printed to stdout.

Actual behaviour

An AttributeError is raised:

Traceback (most recent call last):
  File "/home/ashpool/elrondsdk/erdpy-venv/bin/erdpy", line 8, in <module>
    sys.exit(main())
  File "/home/ashpool/elrondsdk/erdpy-venv/lib/python3.10/site-packages/erdpy/cli.py", line 32, in main
    _do_main()
  File "/home/ashpool/elrondsdk/erdpy-venv/lib/python3.10/site-packages/erdpy/cli.py", line 58, in _do_main
    args.func(args)
  File "/home/ashpool/elrondsdk/erdpy-venv/lib/python3.10/site-packages/erdpy/cli_delegation.py", line 169, in add_new_nodes
    staking_provider.prepare_args_for_add_nodes(args)
  File "/home/ashpool/elrondsdk/erdpy-venv/lib/python3.10/site-packages/erdpy/delegation/staking_provider.py", line 45, in prepare_args_for_add_nodes
    secret_key_bytes, bls_key = parse_validator_pem(validator_pem)
  File "/home/ashpool/elrondsdk/erdpy-venv/lib/python3.10/site-packages/erdpy/wallet/pem.py", line 56, in parse_validator_pem
    pem_file = pem_file.expanduser()
AttributeError: 'str' object has no attribute 'expanduser'

Cause and possible fix

As of 15a2af32c6ccaf07cd42456c4f64900c20439540, many modules have been changed to use pathlib instead of os.path, among them wallet/pem.py. However, some other modules were overlooked, like delegation/staking_provider.py, resulting in code that attempts to treat a str as a pathlib.Path, e.g. by calling .expanduser() on it.

I was able to work around the particular error I encountered by "casting" validator_pem to pathlib.Path just before passing it to parse_validator_pem(), however, a more thorough fix would be to use pathlib universally for working with paths.

ashpool37 avatar Dec 10 '21 13:12 ashpool37

Partially fixed by https://github.com/ElrondNetwork/elrond-sdk-erdpy/pull/102.

andreibancioiu avatar Mar 12 '22 11:03 andreibancioiu

This issue has been inactive for some time and a solution has already been suggested. If the problem still persists, we kindly ask that you open a new issue or join our Discord channel for further assistance. https://discord.gg/multiversxbuilders

schimih avatar Feb 03 '23 16:02 schimih