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

fix: Removing the certification key in case certification is null #215

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/preset_cli/cli/superset/sync/dbt/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ def sync_datasets( # pylint: disable=too-many-locals, too-many-branches, too-ma

# load additional metadata from dbt model definition
model_kwargs = model.get("meta", {}).pop("superset", {})
certification = (
model_kwargs.get("extra", {}).pop("certification")
if "certification" in model_kwargs
else certification or {"details": "This table is produced by dbt"}
)
certification_info = {
"certification": (
model_kwargs.get("extra", {}).pop("certification")
if "certification" in model_kwargs.get("extra", {})
else certification or {"details": "This table is produced by dbt"}
),
}
Comment on lines +89 to +95
Copy link
Member

Choose a reason for hiding this comment

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

Just a nit, but sometimes it's cleaner to use a try/except:

try:
    certification_info = model_kwargs["extra"]["certification"]
except KeyError:
    certification_info = certification or DEFAULT_CERTIFICATION

(and we'd define DEFAULT_CERTIFICATION)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a very good feedback, @betodealmeida! I'm going to merge this PR for now to solve the issue in main, and address this in a future PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Handled this here: #221


filters = {
"database": OneToMany(database["id"]),
Expand All @@ -115,7 +117,11 @@ def sync_datasets( # pylint: disable=too-many-locals, too-many-branches, too-ma
extra = {
"unique_id": model["unique_id"],
"depends_on": "ref('{name}')".format(**model),
"certification": certification,
**(
certification_info
if certification_info["certification"] is not None
else {}
),
**model_kwargs.pop(
"extra",
{},
Expand Down
1 change: 0 additions & 1 deletion tests/cli/superset/sync/dbt/datasets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,6 @@ def test_sync_datasets_null_certification(mocker: MockerFixture) -> None:
{
"unique_id": "model.superset_examples.messages_channels",
"depends_on": "ref('messages_channels')",
"certification": None,
},
),
is_managed_externally=False,
Expand Down