Skip to content
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

chore: clean get_resource #136

Merged
merged 3 commits into from
Oct 26, 2022
Merged

chore: clean get_resource #136

merged 3 commits into from
Oct 26, 2022

Conversation

betodealmeida
Copy link
Member

SupersetClient has 2 methods for retrieving assets from Superset:

  • get_resources, which returns a list of resources (eg, charts).
  • get_resource, which returns a single resource given its ID and type.

Their response is slightly different. The former returns a subset of the JSON response from Superset, containing only the actual asset (it returns response_payload["result"]). The latter returns the full JSON response from Superset, so after the code has to call:

dataset = client.get_dataset(1)["result"]

I cleaned up the client so that only the result is returned, allowing code to be rewritten as:

dataset = client.get_dataset(1)

@@ -394,7 +394,7 @@ def get_resource(self, resource_name: str, resource_id: int) -> Any:
response = self.session.get(url)
validate_response(response)

resource = response.json()
resource = response.json()["result"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we okay with throwing a KeyError if result isn't available?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if the key is not there it's because the Superset API has completely changed, so it's OK. Also, today we'd also raise KeyError, only later in the code.

@betodealmeida betodealmeida merged commit 4181000 into main Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants