Commit fd55e5e
committed
Fix propagating headers across different class instances
There was a bug in login function of RestClientBase which incorrectly
propagated headers across all instances of the class. Fix it.
The empty dictionary was created only once in the parameter list, and
then reused for all following instances.
The bug appears e.g. when trying to change the authorization method
in the same service using redfish library:
1) creating redfish_client with basic authorization adds a header
to a global headers dictionary ('Authorization')
2) creating a totally separate instance of redfish_client with
session fails, because we get unexpected 'Authorization'
header which was created in previous instance and propagated
incorrectly
Simplified example to explain the incorrect use of dictionary parameter:
```
class Example:
def bad_param(self, optional_dict={}):
if not optional_dict:
print('Optional dict is empty, adding something')
optional_dict['some'] = 'thing'
else:
print(f'Optional dict is NOT empty: {optional_dict}')
example1 = Example()
example1.bad_param()
example2 = Example()
example2.bad_param()
```
Signed-off-by: Michał Michalik <michal.michalik.priv@gmail.com>1 parent 79a008d commit fd55e5e
1 file changed
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
986 | 986 | | |
987 | 987 | | |
988 | 988 | | |
989 | | - | |
| 989 | + | |
990 | 990 | | |
991 | 991 | | |
992 | 992 | | |
| |||
1006 | 1006 | | |
1007 | 1007 | | |
1008 | 1008 | | |
| 1009 | + | |
| 1010 | + | |
1009 | 1011 | | |
1010 | 1012 | | |
1011 | 1013 | | |
| |||
0 commit comments