Skip to content

fix(engine): update databend engine spec for dialect version >=0.4.6 - #28627

Merged
rusackas merged 1 commit into
apache:masterfrom
PlaidCloud:databend-engine-spec
Aug 6, 2026
Merged

rusackas merged 1 commit into
apache:masterfrom
PlaidCloud:databend-engine-spec

Conversation

@rad-pat

@rad-pat rad-pat commented May 21, 2024 •

Copy link
Copy Markdown
Contributor

SUMMARY

databend-sqlalchemy moved from the pure-Python databend-py client to a Rust core, and the two disagree about TLS. The old client read secure and defaulted to an http scheme; the Rust core reads sslmode and defaults to https. An unrecognised parameter is not rejected — it is kept as a session variable — so a stored ?secure=false is silently ignored and the connection switches to TLS against a server that may not speak it.

This PR emits sslmode in both directions, still reads the legacy secure spelling 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_uri was declared with *_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, so Database.parameters returned {} for every Databend connection and the form came back empty. This also meant the legacy-secure fallback could never actually run.
  • sslmode=enable (which the driver accepts alongside require) read as unencrypted, so saving the form would rewrite a TLS connection to sslmode=disable.
  • Values were compared case-sensitively, but databend-py parsed secure with asbool — secure=True genuinely meant encrypted.

The two methods now use the same signatures and the URL.create idiom as the other engine specs.

Per @betodealmeida's review, encryption_disable_parameters is also added to BasicParametersMixin, 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.toml bump this PR originally carried is gone — master is already on databend-sqlalchemy>=0.5.5, and sslmode is still the parameter the current driver reads.

On the migration

upgrade() rewrites secure=true|false to sslmode=require|disable. It also pins connections that carry no TLS parameter to sslmode=disable: those were plaintext under databend-py's http default (Superset only ever wrote secure=true, never secure=false), so leaving them alone would let the new https default 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_string sorts 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 secure fallback, the encrypted_extra keyword regression, the mixin's opt-out parameters, and the migration's upgrade/downgrade including the no-TLS-parameter case.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Migration runtime: a single filtered pass over dbs (sqlalchemy_uri LIKE 'databend%') via paginated_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() restores secure, which is semantically but not textually exact — a row that had no TLS parameter before upgrade() returns as secure=false rather than bare, and casing is normalised. Both forms mean the same thing to databend-py.

@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label May 21, 2024
@dosubot dosubot Bot added the data:connect Namespace | Anything related to db connections / integrations label May 21, 2024
@rad-pat

rad-pat commented May 21, 2024

Copy link
Copy Markdown
Contributor Author

@hantmac - as discussed, here is PR for updating superset with latest dialect.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on making your first PR and thank you for contributing to Superset! 🎉 ❤️

We hope to see you in our Slack community too! Not signed up? Use our Slack App to self-register.

@john-bodley

Copy link
Copy Markdown
Member

@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

codecov Bot commented May 22, 2024 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.44444% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.73%. Comparing base (0fc0d21) to head (04f25c3).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
superset/db_engine_specs/databend.py 33.33% 10 Missing ⚠️
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           
Flag Coverage Δ
hive 37.96% <33.33%> (+<0.01%) ⬆️
mysql 57.79% <44.44%> (+<0.01%) ⬆️
postgres 57.84% <44.44%> (+<0.01%) ⬆️
presto 39.87% <33.33%> (+<0.01%) ⬆️
python 59.21% <44.44%> (+<0.01%) ⬆️
sqlite 57.47% <44.44%> (+<0.01%) ⬆️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hantmac

hantmac commented Jun 3, 2024

Copy link
Copy Markdown
Contributor

@hantmac it seems like you maybe added the the Databend engine spec and thus I was wondering whether you would mind reviewing the PR?

Sorry for late response. I will review as soon as possible. Thanks!

@hantmac hantmac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! LGTM!

@rad-pat

rad-pat commented Sep 6, 2024

Copy link
Copy Markdown
Contributor Author

@betodealmeida , any chance of this progressing? Do you want me to rebase against master?

@rad-pat
rad-pat force-pushed the databend-engine-spec branch from 9dda563 to 7027143 Compare January 15, 2025 11:54
@rad-pat
rad-pat requested a review from hantmac January 15, 2025 11:55
@rusackas

Copy link
Copy Markdown
Member

/korbit-review

@korbit-ai korbit-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-review on 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-review command in a comment at the root of your PR.
  • You can ask Korbit to generate a new PR description using the /korbit-generate-pr-description command in any comment on your PR.
  • Too many Korbit comments? I can resolve all my comment threads if you use the /korbit-resolve command 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"}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll try to take a look early next week

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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,
        }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread superset/db_engine_specs/databend.py Resolved
@mistercrunch

Copy link
Copy Markdown
Member

Pending changes + @betodealmeida approval ... Switching to draft to get off of our pile temporarily

@mistercrunch
mistercrunch marked this pull request as draft August 12, 2025 20:25
@rusackas

Copy link
Copy Markdown
Member

@rad-pat any intent to follow through on this one? We'll likely close it soon otherwise.

@rad-pat

rad-pat commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

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

@rusackas

Copy link
Copy Markdown
Member

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.

@rad-pat
rad-pat force-pushed the databend-engine-spec branch from 7027143 to 27a297b Compare June 18, 2026 08:58
@netlify

netlify Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 04f25c3
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a74854751347b0008440ee7
😎 Deploy Preview https://deploy-preview-28627--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@rad-pat
rad-pat marked this pull request as ready for review June 18, 2026 09:00
@rusackas
rusackas self-requested a review June 24, 2026 18:23

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 :)

@rusackas

Copy link
Copy Markdown
Member

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.

@rad-pat

rad-pat commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

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 databend-sqlalchemy>=0.5.5, so the pyproject.toml bump this PR carried is simply gone, and I confirmed sslmode is still the parameter the current driver reads. Master had also merged DatabendConnectEngineSpec into DatabendEngineSpec since; the changes moved across cleanly.

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 secure=* ones. databend-py defaulted to an http scheme and Superset only ever wrote secure=true, so every connection saved with the encryption box unticked has no parameter at all and was plaintext; the Rust core defaults to https and breaks them. Details in the thread above.

@betodealmeida — encryption_disable_parameters is on BasicParametersMixin as you asked, defaulting to {} so nothing else changes behaviour, and I've answered my own question from that thread (short version: no inverse boolean is needed — the disable set only ever needs stripping on the read path).

I also fixed some pre-existing faults in the two methods this PR touches, which is the bulk of the extra diff. Database.parameters was returning {} for every Databend connection — get_parameters_from_uri took *_args and so raised TypeError on the keyword call, and it mutated an immutabledict; both were swallowed by that property's bare except. Net effect: you could create a Databend connection through the dynamic form but reopening it showed an empty form, and the legacy-secure fallback was unreachable. Also sslmode=enable read as unencrypted (the driver accepts it alongside require), which meant a save could silently rewrite a TLS connection to sslmode=disable. Happy to split those into a separate PR if you'd prefer them reviewed apart from the secure→sslmode change — say the word.

@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 encrypted_extra keyword regression, the mixin's opt-out parameters, and the migration's upgrade/downgrade. There were none for these paths before, which is how all of the above survived.

@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Aug 6, 2026
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]>
@rad-pat
rad-pat force-pushed the databend-engine-spec branch from 155e30e to 04f25c3 Compare August 6, 2026 12:59

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rusackas
rusackas merged commit de93a19 into apache:master Aug 6, 2026
69 checks passed
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

@rad-pat
rad-pat deleted the databend-engine-spec branch August 6, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data:connect:databend data:connect Namespace | Anything related to db connections / integrations doc Namespace | Anything related to documentation risk:db-migration PRs that require a DB migration size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants