-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…5943) * Preliminary changes to keep compile from connecting to the warehouse for runtime calls * Adds option to lib to skip connecting to warehouse for compile; adds prelim tests * Removes unused imports * Simplifies test and renames to SqlCompileRunnerNoIntrospection * Updates name in tests * Spacing * Updates test to check for adapter connection call instead of compile and execute * Removes commented line * Fixes test names * Updates plugin to postgres type as snowflake isn't available * Fixes docstring * Fixes formatting * Moves conditional logic out of class * Fixes formatting * Removes commented line * Moves import * Unmoves import * Updates changelog * Adds further info to method docstring (cherry picked from commit f1326f5) Co-authored-by: Rachel <[email protected]>
- Loading branch information
1 parent
6278880
commit 1aee7b3
Showing
3 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
kind: Features | ||
body: This conditionally no-ops warehouse connection at compile depending on an env | ||
var, disabling introspection/queries during compilation only. This is a temporary | ||
solution to more complex permissions requirements for the semantic layer. | ||
time: 2022-09-26T13:06:27.591061-05:00 | ||
custom: | ||
Author: racheldaniel | ||
Issue: "5936" | ||
PR: "5926" |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
import unittest | ||
from unittest import mock | ||
from dbt.contracts.results import RunningStatus | ||
from dbt.lib import compile_sql | ||
from dbt.adapters.postgres import Plugin | ||
|
||
from test.unit.utils import clear_plugin, inject_adapter | ||
|
||
|
||
class MockContext: | ||
def __init__(self, node): | ||
self.timing = [] | ||
self.node = mock.MagicMock() | ||
self.node._event_status = { | ||
"node_status": RunningStatus.Started | ||
} | ||
self.node.is_ephemeral_model = True | ||
|
||
def noop_ephemeral_result(*args): | ||
return None | ||
|
||
class TestSqlCompileRunnerNoIntrospection(unittest.TestCase): | ||
def setUp(self): | ||
self.manifest = {'mock':'manifest'} | ||
self.adapter = Plugin.adapter({}) | ||
self.adapter.connection_for = mock.MagicMock() | ||
self.ephemeral_result = lambda: None | ||
inject_adapter(self.adapter, Plugin) | ||
|
||
def tearDown(self): | ||
clear_plugin(Plugin) | ||
|
||
@mock.patch('dbt.lib._get_operation_node') | ||
@mock.patch('dbt.task.sql.GenericSqlRunner.compile') | ||
@mock.patch('dbt.task.sql.GenericSqlRunner.ephemeral_result', noop_ephemeral_result) | ||
@mock.patch('dbt.task.base.ExecutionContext', MockContext) | ||
def test__compile_and_execute__with_connection(self, mock_compile, mock_get_node): | ||
""" | ||
By default, env var for allowing introspection is true, and calling this | ||
method should defer to the parent method. | ||
""" | ||
mock_get_node.return_value = ({}, None, self.adapter) | ||
compile_sql(self.manifest, 'some/path', None) | ||
|
||
mock_compile.assert_called_once_with(self.manifest) | ||
self.adapter.connection_for.assert_called_once() | ||
|
||
|
||
@mock.patch('dbt.lib._get_operation_node') | ||
@mock.patch('dbt.task.sql.GenericSqlRunner.compile') | ||
@mock.patch('dbt.task.sql.GenericSqlRunner.ephemeral_result', noop_ephemeral_result) | ||
@mock.patch('dbt.task.base.ExecutionContext', MockContext) | ||
def test__compile_and_execute__without_connection(self, mock_compile, mock_get_node): | ||
""" | ||
Ensure that compile is called but does not attempt warehouse connection | ||
""" | ||
with mock.patch.dict(os.environ, {"__DBT_ALLOW_INTROSPECTION": "0"}): | ||
mock_get_node.return_value = ({}, None, self.adapter) | ||
compile_sql(self.manifest, 'some/path', None) | ||
|
||
mock_compile.assert_called_once_with(self.manifest) | ||
self.adapter.connection_for.assert_not_called() |