-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checking for config headers to be both present and non-empty #263
Conversation
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
trino/client.py
Outdated
@@ -579,25 +579,25 @@ def process(self, http_response) -> TrinoStatus: | |||
): | |||
self._client_session.properties.pop(prop, None) | |||
|
|||
if constants.HEADER_SET_SESSION in http_response.headers: | |||
if http_response.headers.get(constants.HEADER_SET_SESSION): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd instead fix the various get_session_property_values
and get_roles_values
etc. functions to properly handle empty values.
That way you can even unit-test those methods directly instead of using mocks.
It also prevents against regressions when those functions get re-used in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, sounds much better to me :)
Change to this approach is in
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
Morning! Just checking in if this is a change we'd like to include, or something we want to discuss more :) |
@derek-pyne I've been travelling so did not get a chance to re-review/merge. I'll get to this starting the weekend/Monday. Sorry about the long wait. |
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
All good! No rush, just checking in |
adc34cb
to
73970d3
Compare
Squashed the commits. Will merge once CI is done. Thanks for the fix. |
Before this change user would receive a ValueError: not enough values to unpack if the session property, role or prepared statements headers existed but had empty values. While Trino itself doesn't send empty headers it's possible for them to be present because of some proxy or gateway sitting between client and the server.
73970d3
to
c412976
Compare
Addresses #262 .
Handles cases where these config headers are present in the request, but with an empty string as their value. Currently, an error is raised when trying to parse the empty strings. This PR addresses this by checking that these headers are not only present, but not empty.
These headers being present with empty values is not normally expected, although we'd like to protect against it for cases like a proxy sitting in between Trino and the client that is altering the headers (which is the case for me).
Notes:
process
that might hit this issue because the values are parsed. HEADER_SET_SESSION, HEADER_SET_ROLE and HEADER_ADDED_PREPARE are currently failing to parse if the header value is emptyNon-technical explanation
Protecting against headers being present but without data
Release notes
( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
(x) Release notes are required, with the following suggested text: