-
Notifications
You must be signed in to change notification settings - Fork 2
fix: create placeholder metrics for failed legacy->cloud translations #15
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/data/metrics/test_cases/with_unresolved_identifier_cloud.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [ | ||
| { | ||
| "data": { | ||
| "id": "metric_with_computed_attribute_aaCompAttrMetric1", | ||
| "type": "metric", | ||
| "attributes": { | ||
| "title": "[ERROR] Metric with computed attribute", | ||
| "tags": ["ERROR"], | ||
| "description": "", | ||
| "content": { | ||
| "format": "#,##0.00", | ||
| "maql": "#Failed MAQL:\n#SELECT COUNT([/gdc/md/dinu996plcf6ajcp6wygnqn952uyom9u/obj/9001])\n\n#Error:\n#Search Cloud Id - Unknown Legacy identifier attr.comp.computedAttr\n\nSELECT SQRT(-1)" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ] |
63 changes: 63 additions & 0 deletions
63
tests/data/metrics/test_cases/with_unresolved_identifier_legacy.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| [ | ||
| { | ||
| "metric": { | ||
| "content": { | ||
| "format": "#,##0.00", | ||
| "tree": { | ||
| "position": { | ||
| "line": 1, | ||
| "column": 14 | ||
| }, | ||
| "type": "metric", | ||
| "content": [ | ||
| { | ||
| "content": [ | ||
| { | ||
| "type": "function", | ||
| "value": "COUNT", | ||
| "position": { | ||
| "column": 21, | ||
| "line": 1 | ||
| }, | ||
| "content": [ | ||
| { | ||
| "value": "/gdc/md/dinu996plcf6ajcp6wygnqn952uyom9u/obj/9001", | ||
| "type": "attribute object", | ||
| "position": { | ||
| "column": 28, | ||
| "line": 1 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "type": "expression", | ||
| "position": { | ||
| "column": 21, | ||
| "line": 1 | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "expression": "SELECT COUNT([/gdc/md/dinu996plcf6ajcp6wygnqn952uyom9u/obj/9001])" | ||
| }, | ||
| "meta": { | ||
| "isProduction": 1, | ||
| "summary": "", | ||
| "contributor": "/gdc/account/profile/5cc081c981561ae1d3f81481b50f002c", | ||
| "updated": "2025-04-10 09:26:53", | ||
| "identifier": "aaCompAttrMetric1", | ||
| "tags": "", | ||
| "uri": "/gdc/md/dinu996plcf6ajcp6wygnqn952uyom9u/obj/9010", | ||
| "title": "Metric with computed attribute", | ||
| "created": "2025-04-10 09:24:10", | ||
| "category": "metric", | ||
| "deprecated": "0", | ||
| "author": "/gdc/account/profile/5cc081c981561ae1d3f81481b50f002c" | ||
| }, | ||
| "links": { | ||
| "explain2": "/gdc/md/dinu996plcf6ajcp6wygnqn952uyom9u/obj/9010/explain2" | ||
| } | ||
| } | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| # (C) 2026 GoodData Corporation | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| """ | ||
| Unit tests for gooddata_legacy2cloud.metrics.utils helper functions. | ||
| """ | ||
|
|
||
| import json | ||
| from types import SimpleNamespace | ||
|
|
||
| from gooddata_legacy2cloud.metrics.utils import ( | ||
| build_placeholder_maql, | ||
| comment_out_lines, | ||
| disable_broken_metric, | ||
| ) | ||
|
|
||
|
|
||
| def test_comment_out_lines_prefixes_every_line(): | ||
| assert comment_out_lines("first line\nsecond line") == "#first line\n#second line" | ||
|
|
||
|
|
||
| def test_build_placeholder_maql_without_extra_message(): | ||
| result = build_placeholder_maql("SELECT COUNT([/gdc/md/project/obj/1])") | ||
|
|
||
| assert result == ( | ||
| "#Failed MAQL:\n#SELECT COUNT([/gdc/md/project/obj/1])\n\nSELECT SQRT(-1)" | ||
| ) | ||
|
|
||
|
|
||
| def test_build_placeholder_maql_defaults_to_error_label(): | ||
| result = build_placeholder_maql( | ||
| "SELECT SUM([/gdc/md/project/obj/2])", "something went wrong" | ||
| ) | ||
|
|
||
| assert result == ( | ||
| "#Failed MAQL:\n#SELECT SUM([/gdc/md/project/obj/2])" | ||
| "\n\n#Error:\n#something went wrong\n\nSELECT SQRT(-1)" | ||
| ) | ||
|
|
||
|
|
||
| def test_build_placeholder_maql_with_custom_label(): | ||
| result = build_placeholder_maql( | ||
| "SELECT SUM([/gdc/md/project/obj/3])", | ||
| "Cannot resolve reference", | ||
| "API Error 400", | ||
| ) | ||
|
|
||
| assert result == ( | ||
| "#Failed MAQL:\n#SELECT SUM([/gdc/md/project/obj/3])" | ||
| "\n\n#API Error 400:\n#Cannot resolve reference\n\nSELECT SQRT(-1)" | ||
| ) | ||
|
|
||
|
|
||
| def test_build_placeholder_maql_with_explicit_no_label(): | ||
| result = build_placeholder_maql( | ||
| "SELECT SUM([/gdc/md/project/obj/4])", "first line\nsecond line", None | ||
| ) | ||
|
|
||
| assert result == ( | ||
| "#Failed MAQL:\n#SELECT SUM([/gdc/md/project/obj/4])" | ||
| "\n\n#first line\n#second line\n\nSELECT SQRT(-1)" | ||
| ) | ||
|
|
||
|
|
||
| def test_disable_broken_metric_without_error_response(): | ||
| metric = { | ||
| "data": { | ||
| "attributes": { | ||
| "title": "My metric", | ||
| "tags": ["existing"], | ||
| "content": {"maql": "SELECT SUM({fact/orders.amount})"}, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| result = disable_broken_metric(metric) | ||
|
|
||
| attributes = result["data"]["attributes"] | ||
| assert attributes["title"] == "[ERROR] My metric" | ||
| assert attributes["tags"] == ["existing", "ERROR"] | ||
| assert attributes["content"]["maql"] == ( | ||
| "#Failed MAQL:\n#SELECT SUM({fact/orders.amount})\n\nSELECT SQRT(-1)" | ||
| ) | ||
|
|
||
|
|
||
| def test_disable_broken_metric_with_no_existing_tags(): | ||
| metric = { | ||
| "data": { | ||
| "attributes": { | ||
| "title": "My metric", | ||
| "tags": None, | ||
| "content": {"maql": "SELECT SUM({fact/orders.amount})"}, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| result = disable_broken_metric(metric) | ||
|
|
||
| assert result["data"]["attributes"]["tags"] == ["ERROR"] | ||
|
|
||
|
|
||
| def test_disable_broken_metric_appends_api_error_detail(): | ||
| metric = { | ||
| "data": { | ||
| "attributes": { | ||
| "title": "My metric", | ||
| "tags": [], | ||
| "content": {"maql": "SELECT SUM({fact/orders.amount})"}, | ||
| } | ||
| } | ||
| } | ||
| error_response = SimpleNamespace( | ||
| status_code=400, | ||
| text=json.dumps({"detail": "Cannot resolve reference"}), | ||
| ) | ||
|
|
||
| result = disable_broken_metric(metric, error_response) | ||
|
|
||
| assert result["data"]["attributes"]["content"]["maql"] == ( | ||
| "#Failed MAQL:\n#SELECT SUM({fact/orders.amount})" | ||
| "\n\n#API Error 400:\n#Cannot resolve reference\n\nSELECT SQRT(-1)" | ||
| ) | ||
|
|
||
|
|
||
| def test_disable_broken_metric_with_non_object_json_error_body(): | ||
| metric = { | ||
| "data": { | ||
| "attributes": { | ||
| "title": "My metric", | ||
| "tags": [], | ||
| "content": {"maql": "SELECT SUM({fact/orders.amount})"}, | ||
| } | ||
| } | ||
| } | ||
| error_response = SimpleNamespace( | ||
| status_code=500, | ||
| text=json.dumps(["Internal Server Error"]), | ||
| ) | ||
|
|
||
| result = disable_broken_metric(metric, error_response) | ||
|
|
||
| assert result["data"]["attributes"]["content"]["maql"] == ( | ||
| "#Failed MAQL:\n#SELECT SUM({fact/orders.amount})" | ||
| '\n\n#API Error 500:\n#["Internal Server Error"]\n\nSELECT SQRT(-1)' | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.