1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

module_utils/vultr.py: Ensure comparison is accurate (#43298)

In query_resource_by_key(), there is an equal comparison that is made to
know if the object we are looking for is present. Due to type difference
this comparison doesn't always retrieve true, even when it should.

This is due to the fact that the value in r_data dict are of type
unicode, while the other can be of type int, float,... .

```
>>> a = u'1'
>>> type(a)
<type 'unicode'>
>>> b = 1
>>> type(b)
<type 'int'>
>>> a == b
False
>>> str(a) == str(b)
True
```

Hence the values, for comparison purposes, are casted into strings.
This commit is contained in:
Yanis Guenane 2018-08-11 10:48:44 +02:00 committed by ansibot
parent 051320a5f5
commit ffcdc53536

View file

@ -217,7 +217,7 @@ class Vultr:
return {}
for r_id, r_data in r_list.items():
if r_data[key] == value:
if str(r_data[key]) == str(value):
self.api_cache.update({
resource: r_data
})