Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post_deploy script should run relative to project root, Fixes #1325. #1340

Merged
merged 6 commits into from
Jul 22, 2024

Conversation

sfc-gh-melnacouzi
Copy link
Contributor

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually on MacOS.
  • I've confirmed that my changes are working by executing CLI's commands manually on Windows.
  • I've confirmed that my changes are up-to-date with the target branch.
  • [] I've described my changes in the release notes.
  • I've described my changes in the section below.

Changes description

Post_deploy script should run relative to project root, Fixes #1325

@sfc-gh-melnacouzi sfc-gh-melnacouzi requested review from a team as code owners July 18, 2024 17:39
@@ -141,13 +145,18 @@ def _execute_sql_script(self, sql_script_path):
This assumes that a relevant warehouse is already active.
Consequently, "use database" will be executed first if it is set in definition file or in the current connection.
"""
with open(sql_script_path) as f:
sql_script = f.read()
env = get_sql_cli_jinja_env(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We exploded snowflake_sql_jinja_render, any reason we couldn't modify the existing abstraction instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we're diverging between how package scripts are executed and how post-deploy scripts are executed. For package scripts, the env is created differently, and AFAICT if a script fails to expand we guarantee that no script is executed. This doesn't appear to be the case here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have refactored to reuse some of the existing package script logic, and also make sure that we check for template errors before executing any of the scripts.

sfc-gh-astus
sfc-gh-astus previously approved these changes Jul 19, 2024
@@ -561,6 +561,27 @@ def create_app_package(self) -> None:
)
)

def _expand_script_templates(
self, env: jinja2.Environment, jinja_context, scripts: List[str]
):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document the return type of this

def _expand_script_templates(
self, env: jinja2.Environment, jinja_context, scripts: List[str]
):
queued_queries = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's a query in this context? The same doesn't sound very meaningful here. Isn't it just script content? I know the name was there before, but it's a good opportunity to clarify.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

self._execute_query(f"use database {self._conn.database}")
sql_script = snowflake_sql_jinja_render(content=sql_script)
self._execute_queries(sql_script)
if database_name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is not None is the typical way to check this, since we shouldn't make a habit of interpreting what it means for a string to be truthy.

Copy link
Contributor

@sfc-gh-cgorrie sfc-gh-cgorrie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, but you could also add snapshot tests for different template errors as what we show users when something goes wrong is somewhat of a contract.

@sfc-gh-melnacouzi sfc-gh-melnacouzi merged commit 5c57ac9 into main Jul 22, 2024
18 checks passed
@sfc-gh-melnacouzi sfc-gh-melnacouzi deleted the melnacouzi-fix-post-install-relative-path branch July 22, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants