Skip to content

[Bug] Incremental models fail with ORA-00955 when database parameter doesn't match service name #193

@nikolber

Description

@nikolber

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When database parameter doesn't match the service parameter:
First run: Successfully creates table in correct schema
Second run: Fails with ORA-00955: name is already used by an existing object
The adapter incorrectly tries to CREATE TABLE instead of running incremental logic because relation detection fails.

Expected Behavior

  1. Create the table on first run
  2. Run incremental logic (MERGE/DELETE+INSERT) on subsequent runs
  3. Work regardless of the database parameter value

Steps To Reproduce

  1. Configure profiles.yml with mismatched database/service:
my_profile:
  target: dev
  outputs:
    dev:
      type: oracle
      user: dbt
      pass: password
      service: MYSERVICE
      database: MYDATABASE# <--  doesn't match service!
      schema: dbt
      host: localhost
      port: 1521
  1. Configure custom schema in dbt_project.yml:
models:
  my_project:
    intermediate:
      +schema: intermediate
  1. Create an incremental model:
-- models/intermediate/test_incremental.sql
 {{
     config(
         materialized='incremental',
         unique_key='id',
         incremental_strategy='merge'
     )
 }}

 select
     1 as id,
     'test' as value
 from dual

 {% if is_incremental() %}
     where 1 = 0  -- No new data on incremental runs for testing
 {% endif %}
  1. Run twice and observe the error:

$ dbt run --select test_incremental
First run succeeds - creates intermediate.test_incremental

$ dbt run --select test_incremental
Second run fails with:
ORA-00955: name is already used by an existing object

Relevant log output using --debug flag enabled

Environment

- OS:Ubuntu 24.04
- Python: Python 3.12.3
- dbt-core: v1.9
- dbt-oracle: 1.9.4

What Oracle database version are you using dbt with?

19c

Additional Context

In our case, local development worked because the database name matched the service name, but in the test environment we encountered this problem.

A workaround was to remove the database parameter entirely from profiles.yml.

After removing it, incremental models work correctly on all subsequent runs.

Suggested fix

Looking at the code in dbt/adapters/oracle/impl.py, the get_relation() method could be modified to ignore the database parameter:

Current code:

def get_relation(self, database: str, schema: str, identifier: str) -> Optional[BaseRelation]:
    if database == 'None':
        database = self.config.credentials.database
    return super().get_relation(database, schema, identifier)

Change to:

def get_relation(self, database: str, schema: str, identifier: str) -> Optional[BaseRelation]:
    # In Oracle database parameter doesn't apply
    # Use None for consistent cache lookups
    return super().get_relation(None, schema, identifier)

Alternatively, the adapter could validate that database matches the actual Oracle database name or document that it should be omitted for Oracle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions