Skip to content

Commit ef0072a

Browse files
authored
Use the ra3_node config (#1750)
1 parent bbbb5c0 commit ef0072a

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Fixes
2+
body: Use the ra3_node config where it was used earlier.
3+
time: 2026-03-12T13:15:31.28122+05:30
4+
custom:
5+
Author: tauhid621
6+
Issue: "1750"

dbt-redshift/src/dbt/adapters/redshift/impl.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ def verify_database(self, database):
188188
if database.startswith('"'):
189189
database = database.strip('"')
190190
expected = self.config.credentials.database
191+
ra3_node = self.config.credentials.ra3_node
191192

192-
if database.lower() != expected.lower() and not self.use_show_apis():
193+
if database.lower() != expected.lower() and not ra3_node and not self.use_show_apis():
193194
raise dbt_common.exceptions.NotImplementedError(
194195
"Cross-db references allowed only in RA3.* node. ({} vs {})".format(
195196
database, expected
@@ -314,8 +315,9 @@ def standardize_grants_dict(self, grants_table: "agate.Table") -> dict:
314315
def _get_catalog_schemas(self, manifest):
315316
# redshift(besides ra3) only allow one database (the main one)
316317
schemas = super(SQLAdapter, self)._get_catalog_schemas(manifest)
318+
allow_multiple_databases = self.config.credentials.ra3_node or self.use_show_apis()
317319
try:
318-
return schemas.flatten(allow_multiple_databases=self.use_show_apis())
320+
return schemas.flatten(allow_multiple_databases=allow_multiple_databases)
319321
except dbt_common.exceptions.DbtRuntimeError as exc:
320322
msg = f"Cross-db references allowed only in {self.type()} RA3.* node. Got {exc.msg}"
321323
raise dbt_common.exceptions.CompilationError(msg)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import pytest
2+
3+
import dbt_common.exceptions
4+
from dbt.adapters.redshift.impl import RedshiftAdapter
5+
6+
7+
@pytest.fixture
8+
def adapter(mocker):
9+
mock_config = mocker.MagicMock()
10+
mock_config.credentials.database = "dev"
11+
mock_config.credentials.ra3_node = False
12+
mock_mp_context = mocker.MagicMock()
13+
adapter = RedshiftAdapter(mock_config, mock_mp_context)
14+
adapter.use_show_apis = lambda: False
15+
return adapter
16+
17+
18+
class TestVerifyDatabase:
19+
"""Tests for verify_database cross-database reference gating."""
20+
21+
def test_same_database_always_passes(self, adapter):
22+
assert adapter.verify_database("dev") == ""
23+
24+
def test_same_database_case_insensitive(self, adapter):
25+
assert adapter.verify_database("DEV") == ""
26+
27+
def test_quoted_database_strips_quotes(self, adapter):
28+
assert adapter.verify_database('"dev"') == ""
29+
30+
def test_cross_db_blocked_by_default(self, adapter):
31+
with pytest.raises(dbt_common.exceptions.NotImplementedError, match="Cross-db"):
32+
adapter.verify_database("other_db")
33+
34+
def test_cross_db_allowed_with_ra3_node(self, adapter):
35+
adapter.config.credentials.ra3_node = True
36+
assert adapter.verify_database("other_db") == ""
37+
38+
def test_cross_db_allowed_with_use_show_apis(self, adapter):
39+
adapter.use_show_apis = lambda: True
40+
assert adapter.verify_database("other_db") == ""
41+
42+
def test_cross_db_allowed_with_both_flags(self, adapter):
43+
adapter.config.credentials.ra3_node = True
44+
adapter.use_show_apis = lambda: True
45+
assert adapter.verify_database("other_db") == ""
46+
47+
def test_cross_db_blocked_without_either_flag(self, adapter):
48+
adapter.config.credentials.ra3_node = False
49+
adapter.use_show_apis = lambda: False
50+
with pytest.raises(dbt_common.exceptions.NotImplementedError, match="Cross-db"):
51+
adapter.verify_database("other_db")

0 commit comments

Comments
 (0)