fix: handle scheme empty string#11842
Conversation
69d4a94 to
9849a46
Compare
|
Thanks @baumgold ! Can you add a test for this? |
|
@NickCrews - It doesn't look like the repo currently has any tests specifically for the trino backend (or any specific backend for that matter) |
@baumgold There are backend-specific tests under each backend implementation (in this case, |
f2afbae to
7608742
Compare
9b06e1f to
976cd7d
Compare
|
@baumgold I just overhauled the test and implementation. Can you see if that is actually testing the behavior you expect? |
|
I think the root cause of the confusion is that the TrinoBackend._from_url() classmethod is converting the host kwarg to be just the hostname part of the url, not the entire url. The trino db api expects the host kwarg to be an entire url, and does scheme inference on it. |
|
Honestly, the trino API kinda sucks. It isn't documented well for one thing. Then it prefers the URL for some args, such as http_scheme. This is the opposite semantics of how ibis prefers kwargs over the URL. But then trino doesn't even consider the user from the URL. So, I don't know if we want to get involved with that can of worms, I think we should maybe just pass through all kwargs directly and do very minimal coercion, and tell all users to refer to the trino docs. |
|
There were no tests added in https://github.com/ibis-project/ibis/pull/9960/changes, so I don't actually totally understand what the behavior is with http vs https vs None coming from this comment. |
| # Do NOT convert to url.hostname, the trino client expects an entire URL | ||
| # to do inference on http vs https, port, etc. | ||
| # https://github.com/trinodb/trino-python-client/blob/2108c38dea79518ffb74370177df2dc95f1e6d96/trino/dbapi.py#L169 | ||
| kwargs["host"] = url |
There was a problem hiding this comment.
I don't think this will work. I believe the url passed in here is expected to have the form trino://<username>:<password>@<hostname>:<port>/<database> if it's passed from ibis.connect. Most likely the scheme would be trino rather than http or https.
ibis/ibis/backends/__init__.py
Lines 1675 to 1775 in 7cc3686
There was a problem hiding this comment.
Ah, that may (I'm not totally sure, what about ibis.trino.connect("https://...")?) be true for the scheme, but the trino library also uses the port and other parts of the URL, so we still want to keep the url as-is.
What do you think the solution should be then?
There was a problem hiding this comment.
Or at the least, if you can write out the expected behavior in terms of test cases, then that will help.
ibis/backends/trino/__init__.py
Outdated
| self, | ||
| user: str = "user", | ||
| auth: str | None = None, | ||
| auth: str | BasicAuthentication | None = None, |
There was a problem hiding this comment.
Probably we should accept any kind of Authentication:
| auth: str | BasicAuthentication | None = None, | |
| auth: str | trino.auth.Authentication | None = None, |
|
@NickCrews - Thanks for your assistance and commits. |
Description of changes
Connecting to a trino database with a user/pass using
http_scheme="https"does not work. I believe this is because thedo_connectfunction does not enter the if statement due to the walrus operator returning the scheme as an empty string which implicitly evaluates to False. This PR fixes that issue. Last modified in #9960.Issues closed