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

Partial parsing bug with empty schema file - ensure None is not passed to load_yaml_text #6494

Merged
merged 4 commits into from
Jan 3, 2023

Conversation

gshank
Copy link
Contributor

@gshank gshank commented Jan 2, 2023

resolves #4850

Description

The "contents" of a file object is defined as Optional[str] but load_yaml_text does not support passing in None from contents. Ensure that if field is set to None, an empty string is passed.

Checklist

@gshank gshank requested review from a team as code owners January 2, 2023 03:34
@cla-bot cla-bot bot added the cla:yes label Jan 2, 2023
@@ -100,8 +100,11 @@
def yaml_from_file(source_file: SchemaSourceFile) -> Dict[str, Any]:
"""If loading the yaml fails, raise an exception."""
path = source_file.path.relative_path
# File contents filed is Optional, and is sometimes None, so ensure
# we are not passing in None to load_yaml_text.
contents = source_file.contents if source_file.contents else ""
Copy link
Contributor

Choose a reason for hiding this comment

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

I can go either way on this, but this could be:
contents = source_file.contents or ""

Taken further, this function could be:

def yaml_from_file(source_file: SchemaSourceFile) -> Dict[str, Any]:
    try:
        return load_yaml_text(source_file.contents or "", source_file.path)
    except ValidationException as e:
        raise YamlLoadFailure(source_file.project_name, source_file.path.relative_path, e)

The initial variables of path and contents are only used once, so the only benefit is readability. However, in both cases I need to refer to the variable definition to see what's being passed in; i.e. contents is forced to have a value, hence is not quite the same as source_file.contents, and path is actually the relative path, and not the absolute path. If these are moved into the function call, it's more readable to me (though that may differ by user). Also, the docstring is basically the code at that point, so it's no longer needed.

As an alternative for the None vs "" issue with load_yaml_text(), should we consider overriding None with "" in load_yaml_text() itself? In other words, will this happen elsewhere? Will we always want to pass in an empty string when we have a None? Or are there valid scenarios where we want to pass in a None for this argument and generate the resulting error?

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 changed yaml_from_file as per your suggestion. I'd rather not change load_yaml_text at this point because we're going to backport this and we want to make backport changes as minimal as possible.

@gshank gshank requested review from a team and aranke January 3, 2023 19:24
@@ -477,6 +477,8 @@ def test_postgres_skip_macros(self):
# initial run so we have a msgpack file
self.setup_directories()
self.copy_file('test-files/model_one.sql', 'models/model_one.sql')
# use empty_schema file for bug #4850
self.copy_file('test-files/empty_schema.yml', 'models/eschema.yml')
Copy link
Contributor

Choose a reason for hiding this comment

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

This test used to run always without this file being present, but now runs always with this file being. So we effectively lost the integration test scenario where this file doesn't exist at all. Do we care about that? We may not; I don't know enough about this functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we don't care about that.

@gshank gshank force-pushed the ct-343-bug_partial_parsing_empty_schema_file branch from 396dedd to 79423ce Compare January 3, 2023 19:31
@@ -1,7 +1,9 @@
import os
# Do not import the os package because we expose this package in jinja
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this comment. I believe the os package is still running, even if only a few objects are pulled in from that namespace. In other words, I don't think this is doing anything different than the original version.

@gshank gshank requested a review from leahwicz January 3, 2023 21:04
@gshank gshank merged commit 6ef3fbb into main Jan 3, 2023
@gshank gshank deleted the ct-343-bug_partial_parsing_empty_schema_file branch January 3, 2023 22:14
@leahwicz leahwicz added backport 1.0.latest Tag for PR to be backported to the 1.0.latest branch backport 1.1.latest backport 1.2.latest This PR will be backported to the 1.2.latest branch backport 1.3.latest labels Jan 3, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2023

The backport to 1.1.latest failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.1.latest 1.1.latest
# Navigate to the new working tree
cd .worktrees/backport-1.1.latest
# Create a new branch
git switch --create backport-6494-to-1.1.latest
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 6ef3fbbf7608955a8828bb99d03ce6aee29ffd79
# Push it to GitHub
git push --set-upstream origin backport-6494-to-1.1.latest
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.1.latest

Then, create a pull request where the base branch is 1.1.latest and the compare/head branch is backport-6494-to-1.1.latest.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2023

The backport to 1.3.latest failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.3.latest 1.3.latest
# Navigate to the new working tree
cd .worktrees/backport-1.3.latest
# Create a new branch
git switch --create backport-6494-to-1.3.latest
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 6ef3fbbf7608955a8828bb99d03ce6aee29ffd79
# Push it to GitHub
git push --set-upstream origin backport-6494-to-1.3.latest
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.3.latest

Then, create a pull request where the base branch is 1.3.latest and the compare/head branch is backport-6494-to-1.3.latest.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2023

The backport to 1.2.latest failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.2.latest 1.2.latest
# Navigate to the new working tree
cd .worktrees/backport-1.2.latest
# Create a new branch
git switch --create backport-6494-to-1.2.latest
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 6ef3fbbf7608955a8828bb99d03ce6aee29ffd79
# Push it to GitHub
git push --set-upstream origin backport-6494-to-1.2.latest
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.2.latest

Then, create a pull request where the base branch is 1.2.latest and the compare/head branch is backport-6494-to-1.2.latest.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2023

The backport to 1.0.latest failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.0.latest 1.0.latest
# Navigate to the new working tree
cd .worktrees/backport-1.0.latest
# Create a new branch
git switch --create backport-6494-to-1.0.latest
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 6ef3fbbf7608955a8828bb99d03ce6aee29ffd79
# Push it to GitHub
git push --set-upstream origin backport-6494-to-1.0.latest
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.0.latest

Then, create a pull request where the base branch is 1.0.latest and the compare/head branch is backport-6494-to-1.0.latest.

leahwicz pushed a commit that referenced this pull request Jan 3, 2023
leahwicz added a commit that referenced this pull request Jan 4, 2023
…d to load_yaml_text (#6494) (#6505)

Co-authored-by: Gerda Shank <gerda@dbtlabs.com>
gshank pushed a commit that referenced this pull request Jan 4, 2023
…d to load_yaml_text (#6494) (#6505)

Co-authored-by: Gerda Shank <gerda@dbtlabs.com>
(cherry picked from commit 6e9ff28)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.0.latest Tag for PR to be backported to the 1.0.latest branch backport 1.1.latest backport 1.2.latest This PR will be backported to the 1.2.latest branch backport 1.3.latest cla:yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-343] partial parse conflicts with generate_schema_name changes
3 participants