Repository navigation
Conversation
…STALL/LOAD Settings that control where DuckDB fetches extensions from (custom_extension_repository, extension_directory, autoinstall_known_extensions, http_proxy, ...) were applied after the extensions had already been installed, so in restricted networks INSTALL reached out to the default repository before the configured one was ever set. These settings are now applied first; all other connector_config settings are still applied after the extensions are loaded. Also quote non-alias `repository` values in `INSTALL ... FROM` so local directories and URLs work, not only aliases such as `community`. Signed-off-by: Tan Akpek <akpektan@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a bug in the DuckDB connection's dependency bootstrap process. When a new cursor is initialized, SQLMesh bootstraps the connection's dependencies (extensions, settings, secrets, filesystems, catalogs) in a fixed order, and the step that installs extensions ran before the step that configured where extensions are fetched from. The bootstrap therefore reached out to the default public repository even when the user had configured an internal mirror or a local directory, which cannot be worked around from configuration. This PR reorders the bootstrap so extension-management settings are applied first.
Problem
BaseDuckDBConnectionConfig._cursor_initcurrently runs in this order on every new cursor:INSTALL <ext>+LOAD <ext>for every entry inextensionsSET <k> = '<v>'for every entry inconnector_configThat means settings which control where extensions come from (
custom_extension_repository,extension_directory,autoinstall_known_extensions,http_proxy, ...) are applied after DuckDB has already tried to fetch the extensions from the defaultextensions.duckdb.orgrepository.In a restricted network (internal Artifactory mirror, air-gapped host, pre-downloaded extension directory) this is a chicken-and-egg problem: there is no way to make
INSTALL httpfslook anywhere other than the default repo, so the connection hangs/fails before the configured repository is ever set. Even a plain local folder cannot be used as a repository because the install runs first.A second, related bug: the per-extension
repositoryvalue is interpolated unquoted intoINSTALL <name> FROM <repository>. That only works for bare aliases (community,core_nightly); a local path orhttps://URL produces a parse error.Fix
connector_configinto two phases around the extension loop:DUCKDB_EXTENSION_SETTINGSset (custom_extension_repository,autoinstall_extension_repository,extension_directory,autoinstall_known_extensions,autoload_known_extensions,allow_community_extensions,allow_extensions_metadata_mismatch,http_proxy,http_proxy_username,http_proxy_password) are applied before anyINSTALL/LOAD;s3_region) only exist once the corresponding extension is loaded.duckdb_settings()and onlySETwhen the value differs" logic (Fix(duckdb): Only SET connector_config values on cursor init if they are different #4981) is kept and factored into a smallapply_settingshelper used by both phases.INSTALL ... FROM <repository>now quotes anything that is not a bare identifier alias, so local directories and URLs work (INSTALL httpfs FROM '/opt/duckdb/extensions').New order:
All settings in
DUCKDB_EXTENSION_SETTINGSwere checked againstduckdb_settings()on DuckDB 1.4.5 and are core (not extension-provided) andSET-able on a live connection.allow_unsigned_extensionsis deliberately excluded because it is startup-only and cannot beSET; the docs call this out.Reproduction (before / after)
INSTALL httpfsruns first and reaches out toextensions.duckdb.org(hangs or fails in a locked-down network); the custom repository is only set afterwards..../v1.4.5/osx_arm64/httpfs.duckdb_extension) and never contacts the default one.Tests
test_duckdb_extension_settings_applied_before_installasserts the relative order ofSET custom_extension_repository/SET autoinstall_known_extensions<INSTALL httpfs<LOAD httpfs<SET memory_limit.test_duckdb_connector_config_without_extensionscovers the no-extensions path.test_duckdb_extension_repository_quoting(parametrized) covers aliases, local paths, URLs and quote escaping;test_duckdb_extension_force_install_with_repositorycoversFORCE INSTALL ... FROM '...'.tests/core/test_connection_config.py -k duckdb,tests/core/engine_adapter/test_duckdb.pyand the DuckDB integration tests (test_connector_config_from_multiple_connections,test_secret_registration_from_multiple_connections) pass;make styleis clean.Docs
docs/integrations/engines/duckdb.md: expanded theextensions/connector_configrows, added an "Extensions" section documenting the dict form (name,repository,force_install), and a sub-section on installing from a custom or offline repository that describes the ordering guarantee.Out of scope
allow_unsigned_extensionsviaduckdb.connect(config=...)(this was removed in Fix: configure duckdb with connector_config settings. #2240; reintroducing it is a separate discussion)._data_file_to_adapterstill ignores the configuration of a second connection pointing at the same database file.