-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Warn on unpinned git packages (#1446) #1453
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
|
||
DOWNLOADS_PATH = None | ||
REMOVE_DOWNLOADS = False | ||
PIN_PACKAGE_URL = 'https://docs.getdbt.com/docs/package-management#section-specifying-package-versions' # noqa | ||
|
||
|
||
def _initialize_downloads(): | ||
|
@@ -215,6 +216,8 @@ class GitPackage(Package): | |
SCHEMA = GIT_PACKAGE_CONTRACT | ||
|
||
def __init__(self, *args, **kwargs): | ||
if 'warn_unpinned' in kwargs: | ||
kwargs['warn-unpinned'] = kwargs.pop('warn_unpinned') | ||
super(GitPackage, self).__init__(*args, **kwargs) | ||
self._checkout_name = hashlib.md5(six.b(self.git)).hexdigest() | ||
self.version = self._contents.get('revision') | ||
|
@@ -252,8 +255,12 @@ def nice_version_name(self): | |
return "revision {}".format(self.version_name()) | ||
|
||
def incorporate(self, other): | ||
# if one is True, make both be True. | ||
warn_unpinned = self.warn_unpinned and other.warn_unpinned | ||
|
||
return GitPackage(git=self.git, | ||
revision=(self.version + other.version)) | ||
revision=(self.version + other.version), | ||
warn_unpinned=warn_unpinned) | ||
|
||
def _resolve_version(self): | ||
requested = set(self.version) | ||
|
@@ -263,6 +270,10 @@ def _resolve_version(self): | |
'{} contains: {}'.format(self.git, requested)) | ||
self.version = requested.pop() | ||
|
||
@property | ||
def warn_unpinned(self): | ||
return self.get('warn-unpinned', True) | ||
|
||
def _checkout(self, project): | ||
"""Performs a shallow clone of the repository into the downloads | ||
directory. This function can be called repeatedly. If the project has | ||
|
@@ -287,6 +298,13 @@ def _checkout(self, project): | |
|
||
def _fetch_metadata(self, project): | ||
path = self._checkout(project) | ||
if self.version[0] == 'master' and self.warn_unpinned: | ||
dbt.exceptions.warn_or_error( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is in the class of warnings that's worth breaking out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, can we format this as:
We show this warning if a revision is unspecified too, so calling out As a part of this, I'll clean up the whole |
||
'Version for {} not pinned - "master" may introduce breaking ' | ||
'changes without warning! See {}' | ||
.format(self.git, PIN_PACKAGE_URL), | ||
log_fmt='WARNING: {}' | ||
) | ||
loaded = project.from_project_root(path, {}) | ||
return ProjectPackageMetadata(loaded) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the intended logic here? This comment sounds to me like
self.warn_unpinned or other.warn_unpinned
, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! My thought was that it should be False if either was False since it means that at least someone knew what they were doing and didn't want to be bothered. I'm not sure why I wrote
True
twice there in that comment.