Skip to content

Fix propagating headers across different class instances#179

Merged
mraineri merged 1 commit intoDMTF:mainfrom
michal-michalik-priv:m2_fix_headers_parameter
Jun 27, 2025
Merged

Fix propagating headers across different class instances#179
mraineri merged 1 commit intoDMTF:mainfrom
michal-michalik-priv:m2_fix_headers_parameter

Conversation

@michal-michalik-priv
Copy link
Copy Markdown
Contributor

@michal-michalik-priv michal-michalik-priv commented Jun 14, 2025

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

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>
@mraineri
Copy link
Copy Markdown
Contributor

Approved 6/27

@mraineri mraineri merged commit 70fa8ed into DMTF:main Jun 27, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants