Skip to content

Commit

Permalink
Merge pull request #520 from splitgraph/bugfix/repo-topics-api
Browse files Browse the repository at this point in the history
sgr cloud load/dump fixes
  • Loading branch information
mildbyte authored Aug 18, 2021
2 parents 6eb8c92 + 546006d commit 34c12ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
15 changes: 1 addition & 14 deletions splitgraph/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def get_headers():
repository
repoTopicsByNamespaceAndRepository {
nodes {
topics
topic
}
}
repoProfileByNamespaceAndRepository {
Expand Down Expand Up @@ -756,19 +756,6 @@ def upsert_metadata(self, namespace: str, repository: str, metadata: Metadata):
Update metadata for a single repository.
"""
response = self._gql(self._prepare_upsert_metadata_gql(namespace, repository, metadata))
if (
response.status_code == 400
and 'Cannot query field \\"createRepoTopicsAgg\\" on type \\"Mutation\\"'
in response.text
):
# TODO: hack, delete when all upgraded.
# We don't yet have API versioning on the GQL side and there's a breaking change
# coming that'll rename createRepoTopic to createRepoTopicsAgg. If there's
# an error calling the latter, rewrite the query to call the former instead.
logging.debug("Using old metadata replacement query")
response = self._gql(
self._prepare_upsert_metadata_gql(namespace, repository, metadata, v1=True)
)
return response

def bulk_upsert_metadata(
Expand Down
6 changes: 2 additions & 4 deletions splitgraph/cloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class RepositoriesYAML(BaseModel):
class MetadataResponse(BaseModel):
class RepoTopicsResponse(BaseModel):
class RepositoryTopics(BaseModel):
topics: List[str]
topic: str

nodes: List[RepositoryTopics]

Expand Down Expand Up @@ -116,9 +116,7 @@ def to_metadata(self) -> Metadata:
return Metadata(
readme=Metadata.Readme(text=profile.readme),
description=profile.description,
topics=[
t for node in self.repoTopicsByNamespaceAndRepository.nodes for t in node.topics
],
topics=[node.topic for node in self.repoTopicsByNamespaceAndRepository.nodes],
sources=profile.sources,
license=profile.license,
extra_metadata=profile.metadata.upstream_metadata if profile.metadata else None,
Expand Down
4 changes: 3 additions & 1 deletion test/splitgraph/commandline/http_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ def _gql_callback(request, uri, response_headers):
_somerepo_2 = {
"namespace": "otheruser",
"repository": "somerepo_2",
"repoTopicsByNamespaceAndRepository": {"nodes": [{"topics": ["topic_1", "topic_2"]}]},
"repoTopicsByNamespaceAndRepository": {
"nodes": [{"topic": "topic_1"}, {"topic": "topic_2"}]
},
"repoProfileByNamespaceAndRepository": {
"description": "Repository Description 2",
"license": None,
Expand Down

0 comments on commit 34c12ca

Please sign in to comment.