From fdabbfeae4d4a40b7f4b7da38249822a0f587164 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Mon, 22 Jan 2024 14:33:23 -0600 Subject: [PATCH 1/4] add slash command template (#32) Co-authored-by: Michelle Ark --- .../ISSUE_TEMPLATE/implementation-ticket.yml | 10 ++++++++ .../ISSUE_TEMPLATE/slash-command-template.md | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/slash-command-template.md diff --git a/.github/ISSUE_TEMPLATE/implementation-ticket.yml b/.github/ISSUE_TEMPLATE/implementation-ticket.yml index 9bc709e9..18b24046 100644 --- a/.github/ISSUE_TEMPLATE/implementation-ticket.yml +++ b/.github/ISSUE_TEMPLATE/implementation-ticket.yml @@ -30,6 +30,16 @@ body: What is the definition of done for this ticket? Include any relevant edge cases and/or test cases validations: required: true + - type: textarea + attributes: + label: Suggested Tests + description: | + Provide scenarios to test. Link to existing similar tests if appropriate. + placeholder: | + 1. Test with no version specified in the schema file and use selection logic on a versioned model for a specific version. Expect pass. + 2. Test with a version specified in the schema file that is no valid. Expect ParsingError. + validations: + required: true - type: textarea attributes: label: Impact to Other Teams diff --git a/.github/ISSUE_TEMPLATE/slash-command-template.md b/.github/ISSUE_TEMPLATE/slash-command-template.md new file mode 100644 index 00000000..059b2498 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/slash-command-template.md @@ -0,0 +1,23 @@ +## Short description + + + +## Acceptance criteria + + + +## Suggested Tests + + + +## Impact to Other Teams + + + +## Will backports be required? + + + +## Context + + From d984a771186d47cc422ea7bbb2ce18a69dedd96e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:55:17 -0600 Subject: [PATCH 2/4] Bump actions/setup-python from 4 to 5 (#26) Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Emily Rockman --- .github/workflows/build.yml | 2 +- .github/workflows/ci_code_quality.yml | 2 +- .github/workflows/ci_tests.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c3b8366b..4ec1f7e6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,7 +41,7 @@ jobs: uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.11' diff --git a/.github/workflows/ci_code_quality.yml b/.github/workflows/ci_code_quality.yml index 7b12e3d5..0e32f5c9 100644 --- a/.github/workflows/ci_code_quality.yml +++ b/.github/workflows/ci_code_quality.yml @@ -41,7 +41,7 @@ jobs: uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.11' diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 03cdffb8..6b967b94 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -46,7 +46,7 @@ jobs: uses: actions/checkout@v3 - name: "Set up Python ${{ matrix.python-version }}" - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} From 4e84585df94a0d39b671be0d6095ba2b20dbe3b1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:57:37 -0600 Subject: [PATCH 3/4] Bump actions/checkout from 3 to 4 (#25) Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Emily Rockman --- .github/workflows/build.yml | 2 +- .github/workflows/ci_code_quality.yml | 2 +- .github/workflows/ci_tests.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4ec1f7e6..035240f4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,7 +38,7 @@ jobs: steps: - name: Check out the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 diff --git a/.github/workflows/ci_code_quality.yml b/.github/workflows/ci_code_quality.yml index 0e32f5c9..b8b33314 100644 --- a/.github/workflows/ci_code_quality.yml +++ b/.github/workflows/ci_code_quality.yml @@ -38,7 +38,7 @@ jobs: steps: - name: Check out the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 6b967b94..87550594 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -43,7 +43,7 @@ jobs: steps: - name: "Check out the repository" - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: "Set up Python ${{ matrix.python-version }}" uses: actions/setup-python@v5 From 8d6947893272be15faf4fac4456cf4b18f902278 Mon Sep 17 00:00:00 2001 From: Peter Webb Date: Tue, 23 Jan 2024 12:48:44 -0500 Subject: [PATCH 4/4] Refactor macro contexts. (#36) * Refactor macro contexts. * Changelog entry. --- .../Under the Hood-20240122-163546.yaml | 6 +++ dbt_common/clients/jinja.py | 42 +++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 .changes/unreleased/Under the Hood-20240122-163546.yaml diff --git a/.changes/unreleased/Under the Hood-20240122-163546.yaml b/.changes/unreleased/Under the Hood-20240122-163546.yaml new file mode 100644 index 00000000..0d32e2e3 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240122-163546.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Clean up macro contexts. +time: 2024-01-22T16:35:46.907999-05:00 +custom: + Author: peterallenwebb + Issue: "35" diff --git a/dbt_common/clients/jinja.py b/dbt_common/clients/jinja.py index 1b6de92b..ca9a4b55 100644 --- a/dbt_common/clients/jinja.py +++ b/dbt_common/clients/jinja.py @@ -3,9 +3,10 @@ import os import tempfile from ast import literal_eval +from collections import ChainMap from contextlib import contextmanager from itertools import chain, islice -from typing import List, Union, Set, Optional, Dict, Any, Iterator, Type, Callable +from typing import Any, Callable, Dict, Iterator, List, Mapping, Optional, Union, Set, Type from typing_extensions import Protocol import jinja2 @@ -99,6 +100,41 @@ def _compile(self, source, filename): return super()._compile(source, filename) # type: ignore +class MacroFuzzTemplate(jinja2.nativetypes.NativeTemplate): + environment_class = MacroFuzzEnvironment + + def new_context( + self, + vars: Optional[Dict[str, Any]] = None, + shared: bool = False, + locals: Optional[Mapping[str, Any]] = None, + ) -> jinja2.runtime.Context: + # This custom override makes the assumption that the locals and shared + # parameters are not used, so enforce that. + if shared or locals: + raise Exception("The MacroFuzzTemplate.new_context() override cannot use the shared or locals parameters.") + + parent = ChainMap(vars, self.globals) if self.globals else vars + + return self.environment.context_class(self.environment, parent, self.name, self.blocks) + + def render(self, *args: Any, **kwargs: Any) -> Any: + if kwargs or len(args) != 1: + raise Exception("The MacroFuzzTemplate.render() override requires exactly one argument.") + + ctx = self.new_context(args[0]) + + try: + return self.environment_class.concat( # type: ignore + self.root_render_func(ctx) # type: ignore + ) + except Exception: + return self.environment.handle_exception() + + +MacroFuzzEnvironment.template_class = MacroFuzzTemplate + + class NativeSandboxEnvironment(MacroFuzzEnvironment): code_generator_class = jinja2.nativetypes.NativeCodeGenerator @@ -171,7 +207,7 @@ def render(self, *args, **kwargs): with :func:`ast.literal_eval`, the parsed value is returned. Otherwise, the string is returned. """ - vars = dict(*args, **kwargs) + vars = args[0] try: return quoted_native_concat(self.root_render_func(self.new_context(vars))) @@ -226,7 +262,7 @@ def get_macro(self): # make_module is in jinja2.environment. It returns a TemplateModule module = template.make_module(vars=self.context, shared=False) macro = module.__dict__[get_dbt_macro_name(name)] - module.__dict__.update(self.context) + return macro @contextmanager