Skip to content

Commit

Permalink
Make flat graph an attribute and build it during runtime initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Sep 13, 2019
1 parent 141bdd6 commit 726004b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/dbt/context/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,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(),
"graph": manifest.flat_graph,
"log": log,
"model": model_dict,
"modules": get_context_modules(),
Expand Down
23 changes: 11 additions & 12 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +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
self.flat_graph = None
super(Manifest, self).__init__()

@staticmethod
Expand Down Expand Up @@ -224,18 +224,17 @@ 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!
def build_flat_graph(self):
"""This attribute is used in context.common by each node, so we want to
only build it once and avoid any concurrency issues around 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
self.flat_graph = {
'nodes': {
k: v.serialize() for k, v in self.nodes.items()
},
}

def find_disabled_by_name(self, name, package=None):
return dbt.utils.find_in_list_by_name(self.disabled, name, package,
Expand Down
1 change: 1 addition & 0 deletions core/dbt/task/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, args, config):
def _runtime_initialize(self):
self.manifest = load_manifest(self.config)
self.linker = compile_manifest(self.config, self.manifest)
self.manifest.build_flat_graph()


class GraphRunnableTask(ManifestTask):
Expand Down

0 comments on commit 726004b

Please sign in to comment.