-
Notifications
You must be signed in to change notification settings - Fork 36
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
chore(py-glaredb): keyword args for connect #1837
Conversation
This alters the pyFunction connect() to have two additional optional arguments `disable_tls` and `cloud_addr`. These arguments match those that are defined in `LocalClientOpts`. **Before**: ``` glaredb.connect([data_dir_or_cloud_url], [spill_path]) ``` **After**: ``` glaredb.connect( [data_dir_or_cloud_url], [spill_path], [disable_tls], [cloud_addr] ) ``` Resolves: #1829
py-glaredb/src/lib.rs
Outdated
disable_tls: Option<bool>, | ||
cloud_addr: Option<String>, |
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.
Ideally these (and spill path) would be kwargs. Otherwise this will get very unwieldy.
https://pyo3.rs/main/function/signature#using-pyo3signature--
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'll make that improvement, thanks
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.
IMO I like what I got it. Do you see any benefit of **kwargs
over this?
#[pyo3(signature = (data_dir_or_cloud_url = None, /, *, spill_path = None, disable_tls = true, cloud_addr = String::from("https://console.glaredb.com")))]
fn connect(
py: Python,
data_dir_or_cloud_url: Option<String>,
spill_path: Option<String>,
disable_tls: bool,
cloud_addr: String,
) -> PyResult<LocalSession> { }
/
defines the end of positional args*
defines the beginning of keyword-only args (it's a separate comma because you can't do*arg=val
)
So this means:
data_dir_or_cloud_url
is always the first (positional) arg- order after that doesn't matter
- all these extra opts have default values and are hard to misconfigure, because by the nature of using a keyword, you have to provide a value!
LMK if you disagree on this. My thinking is that if we did
#[pyo3(signature = (data_dir_or_cloud_url = None, /, **kwargs))]
fn connect(
py: Python,
data_dir_or_cloud_url: Option<String>,
opts: Option<&PyDict>,
) -> PyResult<LocalSession> { }
There would be additional plumbing on opts
that I rather not muck with
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.
Example use:
import glaredb
cloud_url = "<user>:<pass>@<org>.remote.qa.glaredb.com:6443/<db_name>"
conn = glaredb.connect(cloud_url, cloud_addr="https://qa.glaredb.com", disable_tls=False)
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.
This looks reasonable to me, pinging @universalmind303 to see if he has opinions here.
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.
This seems reasonable to me.
A question not really related to this PR, but why do we need cloud_url and cloud_addr? couldn't we infer the addr from the url?
This is a good question and something I originally inferred in the implementation on #1767 For example, see an old commit in that PR here (code not in main): 5e44f62 I admit the code looks a little..strange: let api_url = if host.contains("qa.glaredb.com") {
"https://qa.glaredb.com/api/internal/authenticate/client"
} else {
"https://console.glaredb.com/api/internal/authenticate/client"
}; and it's mostly to do with the asymmetry here:
IMO if we used From review we decided to pass it in as an arg, which is what we do for pgsrv and rpcsrv: glaredb/crates/glaredb/src/args/mod.rs Lines 40 to 83 in f1a540a
I'd be down to revisit/rethink this to clean it up. Appreciate the question! |
This alters the pyFunction
connect
to have two additional optional argumentsdisable_tls
andcloud_addr
. These arguments match those that are defined inLocalClientOpts
.Before
After
data_dir_or_cloud_url
is positional, and all other args are keyword with defaults and variable in orderExample Uses
Local
Hybrid (using keyword args in any order)
Resolves: #1829