-
Notifications
You must be signed in to change notification settings - Fork 34
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
When running dbt run, the adapter attempts to create the configured schema folders in Dremio. If a folder already exists, Dremio Cloud returns a 400 Bad Request with the message: Unable to create folder on source
The current exception handler in _create_folders only suppresses 400 errors containing "Can not create a folder inside a [SOURCE]". Because the error message for an existing folder is different ("An object already exists with that name"), the exception is raised, causing the dbt run to crash.
dbt.adapters.dremio.api.rest.error.DremioBadRequestException: Bad request:: (400 Client Error: Bad Request for url: ...): ({"errorMessage":"Unable to create folder ... on source .... An object already exists with that name.","moreInfo":""})
Expected Behavior
The adapter should detect that the folder already exists based on the error message and swallow the exception (treat it as success/idempotent), allowing dbt run to proceed with the existing folder.
Possible Solution
Update dbt/adapters/dremio/connections.py in the _create_folders method to check for the "already exists" string in the exception message.
Location: dbt/adapters/dremio/connections.py
Proposed Patch:
except DremioBadRequestException as e:
if (
"Can not create a folder inside a [SOURCE]" in e.message
or "An object already exists with that name" in e.message # <--- Add this check
):
logger.debug(f"Ignoring {e}")
else:
raise e
Steps To Reproduce
- Create a folder in Dremio manually or from a previous run (e.g.,
my_dremio_source.my_schema). - Configure a dbt project to use this schema (
+schema: my_schema). - Run
dbt run. - Observe the failure with
DremioBadRequestException.
Environment
macOS Sequoia 15.5
dbt-dremio version: 1.10.0
dbt-core version: 1.10.15
Dremio CloudRelevant log output
Encountered an error:
Bad request:: (400 Client Error: Bad Request for url: https://api.dremio.cloud/v0/projects/405f90b7-8bc5-4c8d-aa6d-843f4e01dfcd/catalog): ({"errorMessage":"Unable to create folder ati-data-science-innovate on source Prod. An object already exists with that name.","moreInfo":""})
Traceback (most recent call last):
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/cli/requires.py", line 178, in wrapper
result, success = func(*args, **kwargs)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/cli/requires.py", line 128, in wrapper
return func(*args, **kwargs)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/cli/requires.py", line 272, in wrapper
return func(*args, **kwargs)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/cli/requires.py", line 303, in wrapper
return func(*args, **kwargs)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/cli/requires.py", line 373, in wrapper
return func(*args, **kwargs)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/cli/requires.py", line 350, in wrapper
return func(*args, **kwargs)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/cli/requires.py", line 390, in wrapper
return func(*args, **kwargs)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/cli/main.py", line 587, in run
results = task.run()
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/task/runnable.py", line 599, in run
result = self.execute_with_hooks(selected_uids)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/task/runnable.py", line 532, in execute_with_hooks
before_run_status = self.before_run(adapter, selected_uids)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/task/run.py", line 1074, in before_run
self.create_schemas(adapter, required_schemas)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/task/runnable.py", line 728, in create_schemas
create_future.result()
File "/Users/rebfer02/.local/share/uv/python/cpython-3.10.13-macos-aarch64-none/lib/python3.10/concurrent/futures/_base.py", line 451, in result
return self.__get_result()
File "/Users/rebfer02/.local/share/uv/python/cpython-3.10.13-macos-aarch64-none/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
raise self._exception
File "/Users/rebfer02/.local/share/uv/python/cpython-3.10.13-macos-aarch64-none/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt_common/utils/executor.py", line 16, in connected
return func(*args, **kwargs)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/task/runnable.py", line 690, in create_schema
adapter.create_schema(relation)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/adapters/dremio/impl.py", line 96, in create_schema
self.connections.create_catalog(relation)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/adapters/dremio/connections.py", line 271, in create_catalog
self._create_folders(database, schema, rest_client)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/adapters/dremio/connections.py", line 446, in _create_folders
raise e
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/adapters/dremio/connections.py", line 439, in _create_folders
rest_client.create_catalog_api(folder_json)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/adapters/dremio/api/rest/client.py", line 99, in create_catalog_api
return _post(
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/adapters/dremio/api/rest/utils.py", line 63, in _post
return _check_error(response, details)
File "/Users/rebfer02/projects/cldsi-dev-support-dbt/.venv/lib/python3.10/site-packages/dbt/adapters/dremio/api/rest/utils.py", line 123, in _check_error
raise DremioBadRequestException("Bad request:" + details, error,
dbt.adapters.dremio.api.rest.error.DremioBadRequestException: Bad request:: (400 Client Error: Bad Request for url: https://api.dremio.cloud/v0/projects/405f90b7-8bc5-4c8d-aa6d-843f4e01dfcd/catalog): ({"errorMessage":"Unable to create folder ati-data-science-innovate on source Prod. An object already exists with that name.","moreInfo":""})