Repository: dbt-labs/dbt-core

Issue:
[CT-845] Rename `try_*` -> `strict_*`
Follow-up to https://github.com/dbt-labs/dbt-core/pull/5107, https://github.com/dbt-labs/dbt-core/issues/5167

Let's rename:
- `try_set` &rarr; `set_strict`
- `try_zip` &rarr; `zip_strict`

Big idea is that `strict_` methods:
- should raise a standard exception if the value cannot be converted to a set / yaml / json, zipped, etc
- should not not allow for a default value to gracefully (silently) fail over to

Timeline:
- Immediate (before Tuesday): Rename these for the second RC of v1.2.0
- Medium-term: Add `fromjson_strict`, `tojson_strict`, `fromyaml_strict`, `toyaml_strict` following the same pattern


Discussion:

Resolving patch:
diff --git a/core/dbt/context/base.py b/core/dbt/context/base.py
--- a/core/dbt/context/base.py
+++ b/core/dbt/context/base.py
@@ -474,19 +474,17 @@ def _set(value: Iterable[Any], default: Any = None) -> Optional[Set[Any]]:
 
     @contextmember
     @staticmethod
-    def try_set(value: Iterable[Any]) -> Set[Any]:
-        """The `try_set` context method can be used to convert any iterable
+    def set_strict(value: Iterable[Any]) -> Set[Any]:
+        """The `set_strict` context method can be used to convert any iterable
         to a sequence of iterable elements that are unique (a set). The
-        difference to the `set` context method is that the `try_set` method
+        difference to the `set` context method is that the `set_strict` method
         will raise an exception on a TypeError.
 
         :param value: The iterable
-        :param default: A default value to return if the `value` argument
-            is not an iterable
 
         Usage:
             {% set my_list = [1, 2, 2, 3] %}
-            {% set my_set = try_set(my_list) %}
+            {% set my_set = set_strict(my_list) %}
             {% do log(my_set) %}  {# {1, 2, 3} #}
         """
         try:
@@ -497,7 +495,7 @@ def try_set(value: Iterable[Any]) -> Set[Any]:
     @contextmember("zip")
     @staticmethod
     def _zip(*args: Iterable[Any], default: Any = None) -> Optional[Iterable[Any]]:
-        """The `try_zip` context method can be used to used to return
+        """The `zip` context method can be used to used to return
         an iterator of tuples, where the i-th tuple contains the i-th
         element from each of the argument iterables.
 
@@ -518,21 +516,19 @@ def _zip(*args: Iterable[Any], default: Any = None) -> Optional[Iterable[Any]]:
 
     @contextmember
     @staticmethod
-    def try_zip(*args: Iterable[Any]) -> Iterable[Any]:
-        """The `try_zip` context method can be used to used to return
+    def zip_strict(*args: Iterable[Any]) -> Iterable[Any]:
+        """The `zip_strict` context method can be used to used to return
         an iterator of tuples, where the i-th tuple contains the i-th
         element from each of the argument iterables. The difference to the
-        `zip` context method is that the `try_zip` method will raise an
+        `zip` context method is that the `zip_strict` method will raise an
         exception on a TypeError.
 
         :param *args: Any number of iterables
-        :param default: A default value to return if `*args` is not
-            iterable
 
         Usage:
             {% set my_list_a = [1, 2] %}
             {% set my_list_b = ['alice', 'bob'] %}
-            {% set my_zip = try_zip(my_list_a, my_list_b) | list %}
+            {% set my_zip = zip_strict(my_list_a, my_list_b) | list %}
             {% do log(my_set) %}  {# [(1, 'alice'), (2, 'bob')] #}
         """
         try:


Test patch:
diff --git a/test/unit/test_context.py b/test/unit/test_context.py
--- a/test/unit/test_context.py
+++ b/test/unit/test_context.py
@@ -190,9 +190,9 @@ def assert_has_keys(required_keys: Set[str], maybe_keys: Set[str], ctx: Dict[str
         "fromyaml",
         "toyaml",
         "set",
-        "try_set",
+        "set_strict",
         "zip",
-        "try_zip",
+        "zip_strict",
         "log",
         "run_started_at",
         "invocation_id",
diff --git a/tests/functional/context_methods/test_builtin_functions.py b/tests/functional/context_methods/test_builtin_functions.py
--- a/tests/functional/context_methods/test_builtin_functions.py
+++ b/tests/functional/context_methods/test_builtin_functions.py
@@ -7,8 +7,8 @@
 {% macro validate_set() %}
     {% set set_result = set([1, 2, 2, 3, 'foo', False]) %}
     {{ log("set_result: " ~ set_result) }}
-    {% set try_set_result = try_set([1, 2, 2, 3, 'foo', False]) %}
-    {{ log("try_set_result: " ~ try_set_result) }}
+    {% set set_strict_result = set_strict([1, 2, 2, 3, 'foo', False]) %}
+    {{ log("set_strict_result: " ~ set_strict_result) }}
 {% endmacro %}
 """
 
@@ -18,17 +18,17 @@
     {% set list_b = ['foo', 'bar'] %}
     {% set zip_result = zip(list_a, list_b) | list %}
     {{ log("zip_result: " ~ zip_result) }}
-    {% set try_zip_result = try_zip(list_a, list_b) | list %}
-    {{ log("try_zip_result: " ~ try_zip_result) }}
+    {% set zip_strict_result = zip_strict(list_a, list_b) | list %}
+    {{ log("zip_strict_result: " ~ zip_strict_result) }}
 {% endmacro %}
 """
 
 models__set_exception_sql = """
-{% set try_set_result = try_set(1) %}
+{% set set_strict_result = set_strict(1) %}
 """
 
 models__zip_exception_sql = """
-{% set try_set_result = try_zip(1) %}
+{% set zip_strict_result = zip_strict(1) %}
 """
 
 
@@ -46,18 +46,18 @@ def test_builtin_set_function(self, project):
         # The order of the set isn't guaranteed so we can't check for the actual set in the logs
         assert "set_result: " in log_output
         assert "False" in log_output
-        assert "try_set_result: " in log_output
+        assert "set_strict_result: " in log_output
 
     def test_builtin_zip_function(self, project):
         _, log_output = run_dbt_and_capture(["--debug", "run-operation", "validate_zip"])
 
         expected_zip = [(1, "foo"), (2, "bar")]
         assert f"zip_result: {expected_zip}" in log_output
-        assert f"try_zip_result: {expected_zip}" in log_output
+        assert f"zip_strict_result: {expected_zip}" in log_output
 
 
 class TestContextBuiltinExceptions:
-    # Assert compilation errors are raised with try_ equivalents
+    # Assert compilation errors are raised with _strict equivalents
     def test_builtin_function_exception(self, project):
         write_file(models__set_exception_sql, project.project_root, "models", "raise.sql")
         with pytest.raises(CompilationException):