Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix digest auth rest sensors #28153
Any REST sensor which is using DIGEST authentication will fail with the following exception stack:
Fundamentally this is because the requests library stores a bunch of important information in thread local storage when the request is prepared, and this is needed when the thread is later used.
To fix this I've delayed preparing until we actually use the request - this does have the impact that we now prepare before every send rather than only once, but that doesn't appear to have much of a cost looking through the requests library and avoids this nasty issue.
Related issue (if applicable): fixes (closed aged issue) #13524
@balloob I'm going crazy looking at these tests...
They seem to be failing as a method of 'None' is passed to request(). This method came straight from the config, which should be setting a default of 'GET' - so I'm at a loss as to how this could have happened. Looking at the test output it seems that none of the default config which should be there is there for the binary sensor. But no failures from the 'normal' sensor...
RestData is a class within sensor, but binary_sensor refers to it. And both sensor and binary_sensor call it in exactly the same way with exactly the same config as far as I can see. So why does binary_sensor fail?!
I must have missed something obvious. Can you spot it?
test_setup_missing_schema: Change the exception to check for to PlatformNotReady. With the change away from prepared statements, we no longer get the MissingSchema error during setup - we get it when we attempt to call the endpoint. Since the result is PlatformNotReady, which is what we want, and the error log clearly contains a note that the schema is incorrect I think this is fine. test_setup_failed_connect & test_setup_timeout: These aren't checking for minimum config, and they're not invoking the correct method to have the default config filled in. Therefore I've just added the correct minimum config so these can continue to test what they're there to test. test_update_request_exception: Testing a request exception with the assert on line 404! Excellent. Anyway, we've moved from using the requests Session object to the requests.request function - so the patch needed to be altered to ensure the RequestException was raised.