Skip to content

Commit

Permalink
fix StopIteration error when publication not found (#7710)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk authored May 30, 2023
1 parent 00a531d commit 45d6145
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230526-153738.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: fix StopIteration error when publication for project not found
time: 2023-05-26T15:37:38.952939-04:00
custom:
Author: michelleark
Issue: "7711"
2 changes: 0 additions & 2 deletions core/dbt/contracts/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ class PublicationMandatory:
@dataclass
@schema_version("publication", 1)
class PublicationArtifact(ArtifactMixin, PublicationMandatory):
"""This represents the <project_name>_publication.json artifact"""

public_models: Dict[str, PublicModel] = field(default_factory=dict)
metadata: PublicationMetadata = field(default_factory=PublicationMetadata)
# list of project name strings
Expand Down
28 changes: 15 additions & 13 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ def __init__(
self.root_project: RuntimeConfig = root_project
self.all_projects: Mapping[str, Project] = all_projects
self.file_diff = file_diff
self.publications = publications
self.publications: Mapping[str, PublicationArtifact] = (
{publication.project_name: publication for publication in publications}
if publications
else {}
)
self.manifest: Manifest = Manifest()
self.new_manifest = self.manifest
self.manifest.metadata = root_project.get_metadata()
Expand Down Expand Up @@ -839,20 +843,18 @@ def build_public_nodes(self) -> bool:

def load_new_public_nodes(self):
for project in self.manifest.project_dependencies.projects:
publication = (
next(p for p in self.publications if p.project_name == project.name)
if self.publications
else None
)
if publication:
publication_config = PublicationConfig.from_publication(publication)
self.manifest.publications[project.name] = publication_config
# Add to dictionary of public_nodes and save id in PublicationConfig
for public_node in publication.public_models.values():
self.manifest.public_nodes[public_node.unique_id] = public_node
else:
try:
publication = self.publications[project.name]
except KeyError:
raise PublicationConfigNotFound(project=project.name)

publication_config = PublicationConfig.from_publication(publication)
self.manifest.publications[project.name] = publication_config

# Add to dictionary of public_nodes and save id in PublicationConfig
for public_node in publication.public_models.values():
self.manifest.public_nodes[public_node.unique_id] = public_node

def is_partial_parsable(self, manifest: Manifest) -> Tuple[bool, Optional[str]]:
"""Compare the global hashes of the read-in parse results' values to
the known ones, and return if it is ok to re-use the results.
Expand Down
6 changes: 5 additions & 1 deletion tests/functional/multi_project/test_publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,14 @@ def models(self):
def test_pub_artifacts(self, project):
write_file(dependencies_yml, "dependencies.yml")

# Dependencies lists "marketing" project, but no publication file found
# Dependencies lists "marketing" project, but no publications provided
with pytest.raises(PublicationConfigNotFound):
run_dbt(["parse"])

# Dependencies lists "marketing" project, but no "marketing" publication provided
with pytest.raises(PublicationConfigNotFound):
run_dbt(["parse"], publications=[PublicationArtifact(project_name="not_marketing")])

# Provide publication and try again
m_pub_json = marketing_pub_json.replace("test_schema", project.test_schema)
publications = [PublicationArtifact.from_dict(json.loads(m_pub_json))]
Expand Down

0 comments on commit 45d6145

Please sign in to comment.