-
Notifications
You must be signed in to change notification settings - Fork 381
Fix(duckdb): Only SET connector_config values on cursor init if they are different #4981
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -348,11 +348,28 @@ def init(cursor: duckdb.DuckDBPyConnection) -> None: | |||||
| except Exception as e: | ||||||
| raise ConfigError(f"Failed to load extension {extension['name']}: {e}") | ||||||
|
|
||||||
| for field, setting in self.connector_config.items(): | ||||||
| try: | ||||||
| cursor.execute(f"SET {field} = '{setting}'") | ||||||
| except Exception as e: | ||||||
| raise ConfigError(f"Failed to set connector config {field} to {setting}: {e}") | ||||||
| if self.connector_config: | ||||||
| option_names = list(self.connector_config) | ||||||
| in_part = ",".join(["?" for _ in range(len(option_names))]) | ||||||
|
|
||||||
| cursor.execute( | ||||||
| f"SELECT name, value FROM duckdb_settings() WHERE name IN ({in_part})", | ||||||
| option_names, | ||||||
| ) | ||||||
|
|
||||||
| existing_values = {r[0]: r[1] for r in cursor.fetchall()} | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nit: maybe something more explicit like this so that it's more clear when going through the code
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, it didnt even occur to me to unpack the tuple like that. will update |
||||||
|
|
||||||
| # only set connector_config items if the values differ from what is already set | ||||||
| # trying to set options like 'temp_directory' even to the same value can throw errors like: | ||||||
| # Not implemented Error: Cannot switch temporary directory after the current one has been used | ||||||
| for field, setting in self.connector_config.items(): | ||||||
| if existing_values.get(field) != setting: | ||||||
| try: | ||||||
| cursor.execute(f"SET {field} = '{setting}'") | ||||||
| except Exception as e: | ||||||
| raise ConfigError( | ||||||
| f"Failed to set connector config {field} to {setting}: {e}" | ||||||
| ) | ||||||
|
|
||||||
| if self.secrets: | ||||||
| duckdb_version = duckdb.__version__ | ||||||
|
|
||||||
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.
nit: this should achieve the same