Skip to content
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

Merged
merged 1 commit into from
Oct 31, 2022

Conversation

derek-pyne
Copy link
Contributor

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:

  • Added checks for all headers in 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 empty
  • The test reproduces the error, but I don't fully understand the mocking that is happening. Looking for guidance if there is a different preferred way of testing this

Non-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:

* Fix value error with present but empty headers. ([#262](https://github.com/trinodb/trino-python-client/issues/262))

@cla-bot
Copy link

cla-bot bot commented Oct 13, 2022

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):
Copy link
Member

@hashhar hashhar Oct 13, 2022

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.

Copy link
Contributor Author

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

@cla-bot
Copy link

cla-bot bot commented Oct 13, 2022

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

@derek-pyne
Copy link
Contributor Author

Morning! Just checking in if this is a change we'd like to include, or something we want to discuss more :)

@hashhar
Copy link
Member

hashhar commented Oct 27, 2022

@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.

@hashhar
Copy link
Member

hashhar commented Oct 27, 2022

@cla-bot check

@cla-bot cla-bot bot added the cla-signed label Oct 27, 2022
@cla-bot
Copy link

cla-bot bot commented Oct 27, 2022

The cla-bot has been summoned, and re-checked this pull request!

@derek-pyne
Copy link
Contributor Author

@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.

All good! No rush, just checking in

@hashhar hashhar force-pushed the present_but_empty_headers branch from adc34cb to 73970d3 Compare October 31, 2022 09:29
@hashhar
Copy link
Member

hashhar commented Oct 31, 2022

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.
@hashhar hashhar force-pushed the present_but_empty_headers branch from 73970d3 to c412976 Compare October 31, 2022 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants