netbox-community / pynetbox

Python API client library for Netbox.
Apache License 2.0
567 stars 168 forks source link

String concatenation without type casting can cause `TypeError` #538

Closed nautics889 closed 1 year ago

nautics889 commented 1 year ago

There are a couple of lines in pynetbox/core/endpoint.py module having string concatenation without type casting. Line 461:

            raise ValueError(
                "Objects passed must be list[dict|Record] - was " + type(objects)
            )

Line 475:

                raise ValueError(
                    "Object passed must be dict|Record - was " + type(objects)
                )

This obviously can lead to TypeError:

>>> 'Some string  ' + type(something)
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2022.3.2\plugins\python\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
TypeError: can only concatenate str (not "type") to str

It should have explicit type casting via str() like, e. g. like at this line.


As for me the most readable solution would be to use .format() (like there).

abhi1693 commented 1 year ago

Fixed with #539