Skip to content

Commit

Permalink
Stop overriding template context
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-fcampbell committed Oct 17, 2024
1 parent e00107f commit 9d15792
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
9 changes: 0 additions & 9 deletions src/snowflake/cli/_plugins/nativeapp/v2_conversions/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,6 @@ def wrapper(*args, **kwargs):

# Override the project definition so that the command operates on the new entities
cm.override_project_definition = pdfv2

# Override the template context so that templates refer to the new entities
# Reuse the old ctx.env and other top-level keys in the template context
# since they don't change between v1 and v2
pdfv2_dump = pdfv2.model_dump(
exclude_none=True, warnings=False, by_alias=True
)
new_ctx = pdfv2_dump | dict(env=cm.template_context["ctx"]["env"])
cm.override_template_context = cm.template_context | dict(ctx=new_ctx)
elif single_app_and_package:
package_entity_id = kwargs.get("package_entity_id", "")
app_entity_id = kwargs.get("app_entity_id", "")
Expand Down
3 changes: 0 additions & 3 deletions src/snowflake/cli/api/cli_global_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class _CliGlobalContextManager:
# Consider changing the way this calculation is provided to commands
# in order to remove this logic (then make project_definition a non-cloned @property)
override_project_definition: ProjectDefinition | None = None
override_template_context: dict | None = None

_definition_manager: DefinitionManager | None = None

Expand Down Expand Up @@ -98,8 +97,6 @@ def project_root(self) -> Path:

@property
def template_context(self) -> dict:
if self.override_template_context:
return self.override_template_context
return self._definition_manager_or_raise().template_context

@property
Expand Down
4 changes: 2 additions & 2 deletions tests/project/test_project_definition_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ def test_v1_to_v2_conversion_in_memory_package_scripts(temp_dir):
assert Path(package_script_filename).read_text() == package_script

# But the converted definition has a reference to a tempfile
# that contains the converted package script
# that contains the literal package name
assert (
Path(definition_v2.entities["pkg"].meta.post_deploy[0].sql_script).read_text()
== "select '<% ctx.entities.pkg.identifier %>';"
== f"select '{definition_v2.entities['pkg'].fqn.name}';"
)


Expand Down

0 comments on commit 9d15792

Please sign in to comment.