diff --git a/CHANGELOG.md b/CHANGELOG.md index 72596c838c0..dea5d399d50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## dbt 0.14.1 ### Breaking changes - - the undocumented "graph" variable was removed from the parsing context ([#1615](https://github.com/fishtown-analytics/dbt/pull/1615)) + - the undocumented "graph" variable's "macros" field was removed from the parsing context ([#1615](https://github.com/fishtown-analytics/dbt/pull/1615)) ## dbt 0.14.0 - Wilt Chamberlain (July 10, 2019) diff --git a/core/dbt/context/common.py b/core/dbt/context/common.py index 21e5eaf987d..1536672e81d 100644 --- a/core/dbt/context/common.py +++ b/core/dbt/context/common.py @@ -398,6 +398,7 @@ def generate_base(model, model_dict, config, manifest, source_config, "exceptions": dbt.exceptions.wrapped_exports(model), "execute": provider.execute, "flags": dbt.flags, + "graph": manifest.to_flat_graph(), "log": log, "model": model_dict, "modules": get_context_modules(), diff --git a/core/dbt/contracts/graph/manifest.py b/core/dbt/contracts/graph/manifest.py index 0fcadbdd36e..432564eaca7 100644 --- a/core/dbt/contracts/graph/manifest.py +++ b/core/dbt/contracts/graph/manifest.py @@ -185,6 +185,7 @@ def __init__(self, nodes, macros, docs, generated_at, disabled, self.generated_at = generated_at self.metadata = metadata self.disabled = disabled + self._flat_graph = None super(Manifest, self).__init__() @staticmethod @@ -223,6 +224,19 @@ def serialize(self): 'disabled': [v.serialize() for v in self.disabled], } + def to_flat_graph(self): + """This function gets called in context.common by each node, so we want + to cache it. Make sure you don't call this until you're done with + building your manifest! + """ + if self._flat_graph is None: + self._flat_graph = { + 'nodes': { + k: v.serialize() for k, v in self.nodes.items() + }, + } + return self._flat_graph + def find_disabled_by_name(self, name, package=None): return dbt.utils.find_in_list_by_name(self.disabled, name, package, NodeType.refable()) diff --git a/core/dbt/graph/selector.py b/core/dbt/graph/selector.py index 0f37ce08347..78e55823296 100644 --- a/core/dbt/graph/selector.py +++ b/core/dbt/graph/selector.py @@ -325,6 +325,10 @@ def select(self, query): selected = self.get_selected(include, exclude, resource_types, tags, required) + # if you haven't selected any nodes, return that so we can give the + # nice "no models selected" message. + if not selected: + return selected # we used to carefully go through all node ancestors and add those if # they were ephemeral. Sadly, the algorithm we used ended up being # O(n^2). Instead, since ephemeral nodes are almost free, just add all