Repository navigation
fix(engine): update databend engine spec for dialect version >=0.4.6 - #28627
Conversation
|
@hantmac - as discussed, here is PR for updating superset with latest dialect. |
|
@hantmac it seems like you maybe added the the Databend engine spec and thus I was wondering whether you would mind reviewing the PR? |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #28627 +/- ##
=======================================
Coverage 65.73% 65.73%
=======================================
Files 2843 2843
Lines 162653 162656 +3
Branches 37239 37238 -1
=======================================
+ Hits 106912 106919 +7
+ Misses 53648 53644 -4
Partials 2093 2093
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Sorry for late response. I will review as soon as possible. Thanks! |
|
@betodealmeida , any chance of this progressing? Do you want me to rebase against master? |
9dda563 to
7027143
Compare
|
/korbit-review |
There was a problem hiding this comment.
I've completed my review and didn't find any issues.
Files scanned
| File Path | Reviewed |
|---|---|
| superset/db_engine_specs/databend.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Need a new review? Comment
/korbit-reviewon this PR and I'll review your latest changes.Korbit Guide: Usage and Customization
Interacting with Korbit
- You can manually ask Korbit to review your PR using the
/korbit-reviewcommand in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-descriptioncommand in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolvecommand in any comment on your PR.- Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
- Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.
Customizing Korbit
- Check out our docs on how you can make Korbit work best for you and your team.
- Customize Korbit for your organization through the Korbit Console.
Current Korbit Configuration
General Settings
Setting Value Review Schedule Automatic excluding drafts Max Issue Count 10 Automatic PR Descriptions ❌ Issue Categories
Category Enabled Documentation ✅ Logging ✅ Error Handling ✅ Readability ✅ Design ✅ Performance ✅ Security ✅ Functionality ✅ Feedback and Support
Note
Korbit Pro is free for open source projects 🎉
Looking to add Korbit to your team? Get started with a free 2 week trial here
| parameters_schema = DatabendParametersSchema() | ||
| encryption_parameters = {"secure": "true"} | ||
| encryption_parameters = {"sslmode": "require"} | ||
| encryption_disable_parameters = {"sslmode": "disable"} |
There was a problem hiding this comment.
Oh, this is nice! If it's not asking too much, can you add this to the BasicParametersMixin as well, and update the logic of build_sqlalchemy_uri and get_parameters_from_uri to use it?
There was a problem hiding this comment.
OK, I'll try to take a look early next week
There was a problem hiding this comment.
@betodealmeida, it seems straightforward to add the encryption_disable_parameters to the mixin, and to use it in build_sqlalchemy_uri based on encryption True/False parameter, but I'm not sure how to use it sensibly in get_parameters_from_uri - either encryption param is True or False determined by if the encryption_parameters are set.
Here is where I'm struggling to make sense of it. I'm not sure a separate parameter makes sense
def get_parameters_from_uri( # pylint: disable=unused-argument
cls, uri: str, encrypted_extra: dict[str, Any] | None = None
) -> BasicParametersType:
url = make_url_safe(uri)
query = {
key: value
for (key, value) in url.query.items()
if (key, value) not in cls.encryption_parameters.items()
}
encryption = bool(cls.encryption_parameters) and all(
item in url.query.items() for item in cls.encryption_parameters.items()
)
# The opposite, does this make sense?
disable_encryption = bool(cls.encryption_disable_parameters) and all(
item in url.query.items()
for item in cls.encryption_disable_parameters.items()
)
return {
"username": url.username,
"password": url.password,
"host": url.host,
"port": url.port,
"database": url.database,
"query": query,
"encryption": encryption # and not disable_encryption,
}
There was a problem hiding this comment.
Done — encryption_disable_parameters is now on BasicParametersMixin, with build_sqlalchemy_uri applying it on the else branch and get_parameters_from_uri stripping it. It defaults to {}, so query.update({}) is a no-op and no other spec changes behaviour.
To answer my own question from last time: there's no need for an inverse boolean. encryption still derives from encryption_parameters alone — the disable set's only job in the read path is to be removed, so it doesn't survive into query and reappear as a user-supplied extra parameter. Once I framed it that way the asymmetry I was stuck on went away.
One subtlety worth flagging for whoever reviews it: the stripping can't merge the two dicts. They typically share a key with different values (sslmode=require / sslmode=disable), so {**enable, **disable} would keep only one and leak the other. It builds a list of .items() pairs from both instead.
DatabendEngineSpec still overrides both methods, because it needs the __default__ database substitution, the legacy secure fallback, and a bare databend:// scheme (the mixin builds engine+default_driver, which here would be databend+databend:// and would change every stored URI). So the mixin change is generic groundwork rather than something Databend routes through — happy to take it back out if you'd rather it landed with its first real consumer.
|
Pending changes + @betodealmeida approval ... Switching to draft to get off of our pile temporarily |
|
@rad-pat any intent to follow through on this one? We'll likely close it soon otherwise. |
@rusackas, this is a blast from the past - we apply this change to every release we build so that we connect to Databend ok. There were some comments, and I replied but never got any further response. This works for us as it stands, should not require any database migration to upgrade existing connections. If you're happy, I can rebase on master. |
|
Thanks again @rad-pat - trying to get caught up on PRs again :P The rebase is still a good idea here, and we'd love to see it through, but the Databend dialect has moved on well past 0.4.6 since. If the connection-param change is still needed against the current driver, the touchups here would be welcomed, or a fresh PR against master might be the easiest path. |
7027143 to
27a297b
Compare
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
rusackas
left a comment
There was a problem hiding this comment.
@rad-pat thanks for sticking with this one. The one thing from @betodealmeida's review that's still open is the migration to update existing connection URLs.
It matters because the parsing here only repopulates the form... the stored sqlalchemy_uri (e.g. ?secure=false) still gets handed to the driver as-is, so on existing installs the >=0.4.6 bump could break those connections unless we rewrite them.
Shouldn't be much: a migration that loads the databend databases and swaps secure=true→sslmode=require / secure=false→sslmode=disable in the stored URI. Happy to write it up and push the commit to this branch if you'd rather I take it... just say the word and I'll take a crack at it. Then we'll re-review :)
|
Turns out I can't actually push to this fork/branch, so I can't help here. Would love to see this through though, one way or another. |
27a297b to
155e30e
Compare
|
Rebased onto master and pushed — both outstanding review points are addressed, and the branch is conflict-free again. @rusackas — thanks for the nudge, and sorry it sat so long. Two things resolved themselves on the rebase: master is already on The migration you asked for is in. Digging into it turned up something I hadn't expected — connections with no TLS parameter need migrating too, not just @betodealmeida — I also fixed some pre-existing faults in the two methods this PR touches, which is the bulk of the extra diff. @hantmac — you approved this a while back; the scope has grown since, so it's worth another look from a Databend angle if you have time, particularly the migration's treatment of parameter-less URIs. Tests: unit coverage added for the build/parse round trip, the legacy fallback, the |
databend-sqlalchemy moved from the pure-Python databend-py client to a
Rust core, which reads sslmode rather than secure. An unrecognised
parameter is not rejected but kept as a session variable, so a stored
secure value is silently ignored while the scheme falls back to https --
breaking plaintext connections rather than reporting anything.
Emit sslmode in both directions and keep reading the legacy spelling, so
existing connections still populate the form. The mode is always stated
explicitly: the driver does not infer TLS from the port, so an
unencrypted connection needs sslmode=disable rather than the parameter
simply being omitted.
Fix two long-standing faults in the same methods, which together made
Database.parameters return {} for every Databend connection and left the
dynamic form empty. get_parameters_from_uri took *_args, so the keyword
call from Database.parameters raised TypeError, and it mutated
url.query, which is an immutabledict. Both were swallowed by that
property's bare except. While here, align the two methods with the
signatures and URL.create idiom used by the other specs, recognise the
sslmode=enable spelling the driver also accepts, and compare values
case-insensitively -- databend-py parsed secure with asbool, so
secure=True meant encrypted.
Add encryption_disable_parameters to BasicParametersMixin so the pattern
is available to any spec whose driver needs an explicit opt-out. It
defaults to an empty dict, leaving every other spec unaffected.
Migrate stored connections to the parameter the driver now reads.
Connections with no TLS parameter at all are migrated to sslmode=disable
rather than left alone: databend-py defaulted to an http scheme and
Superset only ever wrote secure=true, so these were plaintext and the new
https default would break them.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
155e30e to
04f25c3
Compare
rusackas
left a comment
There was a problem hiding this comment.
Thanks for the deep dive, @rad-pat — this is exactly the fix, migration and test coverage the earlier review was asking for. Verified the sslmode/secure round-trip logic and the migration's in-place query rewrite, all green. Merging.
|
Bito Automatic Review Skipped – PR Already Merged |
SUMMARY
databend-sqlalchemymoved from the pure-Pythondatabend-pyclient to a Rust core, and the two disagree about TLS. The old client readsecureand defaulted to anhttpscheme; the Rust core readssslmodeand defaults tohttps. An unrecognised parameter is not rejected — it is kept as a session variable — so a stored?secure=falseis silently ignored and the connection switches to TLS against a server that may not speak it.This PR emits
sslmodein both directions, still reads the legacysecurespelling so existing connections repopulate the form, and migrates stored URIs.While in the same two methods, it fixes some long-standing faults that made the dynamic form unusable for Databend:
get_parameters_from_uriwas declared with*_args, so the keyword call fromDatabase.parametersraisedTypeError; and it mutatedurl.query, which is animmutabledict. Both were swallowed by that property's bareexcept, soDatabase.parametersreturned{}for every Databend connection and the form came back empty. This also meant the legacy-securefallback could never actually run.sslmode=enable(which the driver accepts alongsiderequire) read as unencrypted, so saving the form would rewrite a TLS connection tosslmode=disable.databend-pyparsedsecurewithasbool—secure=Truegenuinely meant encrypted.The two methods now use the same signatures and the
URL.createidiom as the other engine specs.Per @betodealmeida's review,
encryption_disable_parametersis also added toBasicParametersMixin, for drivers that need an explicit opt-out rather than treating absence of the encryption parameters as "off". It defaults to an empty dict, so no other spec changes behaviour.The
pyproject.tomlbump this PR originally carried is gone — master is already ondatabend-sqlalchemy>=0.5.5, andsslmodeis still the parameter the current driver reads.On the migration
upgrade()rewritessecure=true|falsetosslmode=require|disable. It also pins connections that carry no TLS parameter tosslmode=disable: those were plaintext underdatabend-py'shttpdefault (Superset only ever wrotesecure=true, neversecure=false), so leaving them alone would let the newhttpsdefault break exactly the connections the migration exists to protect.The query string is edited one parameter at a time rather than parsed and re-rendered, because
URL.render_as_stringsorts and re-encodes the whole query and would rewrite unrelated parameters on every touched row.TESTING INSTRUCTIONS
Validate against a Databend instance, over both a TLS and a plaintext endpoint, creating a connection through the dynamic form and reopening it to confirm the fields repopulate.
Unit tests cover the URI build/parse round trip, the legacy
securefallback, theencrypted_extrakeyword regression, the mixin's opt-out parameters, and the migration's upgrade/downgrade including the no-TLS-parameter case.ADDITIONAL INFORMATION
Migration runtime: a single filtered pass over
dbs(sqlalchemy_uri LIKE 'databend%') viapaginated_update, touching only Databend rows. On any realistic instance this is a handful of rows and completes in well under a second; no downtime expected.downgrade()restoressecure, which is semantically but not textually exact — a row that had no TLS parameter beforeupgrade()returns assecure=falserather than bare, and casing is normalised. Both forms mean the same thing todatabend-py.