From 98962f3ba96db83b0cc80c8e8a3a11e9144722a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Je=C5=A1ke?= Date: Thu, 26 Nov 2026 11:30:11 +0100 Subject: [PATCH 1/2] feat(gooddata-sdk): keep five more automation fields in the layout CatalogDeclarativeAutomation modelled 17 of the API's 25 fields, so get_declarative_automations dropped the rest and a put could not set them. It now keeps evaluation_mode, analytical_dashboard, external_recipients, image_exports and slides_exports, with a new ImageExportRequest for the image export payload. SlidesExportRequest gains timezone_id, which the API also stores. SlidesExportRequest named the template templateId, which the client model does not know, so a read dropped it. It is now template_id; templateId still works, maps onto it and warns as deprecated. alert, dashboard_tabular_exports and raw_exports carry a full execution (AFM filters, measures, conditions) and are left for a separate change (F1-3131). The server fills in evaluation_mode, so the layout test now expects its default on the read. jira: F1-3069 risk: low Co-Authored-By: Claude Opus 5.5 --- .../gooddata-sdk/src/gooddata_sdk/__init__.py | 3 + .../gooddata_sdk/catalog/export/request.py | 38 +++++++++++ .../declarative_model/workspace/automation.py | 38 +++++++++++ .../tests/catalog/test_catalog_workspace.py | 4 +- .../test_declarative_automations.py | 63 +++++++++++++++++++ 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 packages/gooddata-sdk/tests/catalog/unit_tests/test_declarative_automations.py diff --git a/packages/gooddata-sdk/src/gooddata_sdk/__init__.py b/packages/gooddata-sdk/src/gooddata_sdk/__init__.py index 018b1cf91..da95627fb 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/__init__.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/__init__.py @@ -90,6 +90,7 @@ ExportRequest, ExportSettings, GrandTotalsPosition, + ImageExportRequest, SlidesExportRequest, VisualExportRequest, ) @@ -597,6 +598,7 @@ "HLLType": "gooddata_sdk.catalog.organization.service", "HLL_TYPE_SETTING_ID": "gooddata_sdk.catalog.organization.service", "HLL_TYPE_SETTING_TYPE": "gooddata_sdk.catalog.organization.service", + "ImageExportRequest": "gooddata_sdk.catalog.export.request", "InlineFilter": "gooddata_sdk.compute.model.filter", "InlineMetric": "gooddata_sdk.compute.model.metric", "KeyPairCredentials": "gooddata_sdk.catalog.entity", @@ -875,6 +877,7 @@ "HLLType", "HLL_TYPE_SETTING_ID", "HLL_TYPE_SETTING_TYPE", + "ImageExportRequest", "InlineFilter", "InlineMetric", "KeyPairCredentials", diff --git a/packages/gooddata-sdk/src/gooddata_sdk/catalog/export/request.py b/packages/gooddata-sdk/src/gooddata_sdk/catalog/export/request.py index 7cb9cc8a2..2c40040b4 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/catalog/export/request.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/catalog/export/request.py @@ -2,11 +2,13 @@ from __future__ import annotations from typing import Literal +from warnings import warn from attrs import define from gooddata_api_client.model.custom_label import CustomLabel as ApiCustomLabel from gooddata_api_client.model.custom_metric import CustomMetric as ApiCustomMetric from gooddata_api_client.model.custom_override import CustomOverride as ApiCustomOverride +from gooddata_api_client.model.image_export_request import ImageExportRequest as ImageExportRequestApi from gooddata_api_client.model.settings import Settings as ApiSettings from gooddata_api_client.model.slides_export_request import SlidesExportRequest as SlidesExportRequestApi from gooddata_api_client.model.tabular_export_request import TabularExportRequest @@ -137,6 +139,8 @@ class SlidesExportRequest(Base): dashboard_id (str): Dashboard identifier. file_name (str): File name to be used for retrieving the PDF document. metadata (Optional[Dict[str, bool]]): Optional dictionary containing settings for the export request. + template_id (Optional[str]): Export template identifier. + templateId (Optional[str]): Deprecated, use template_id. """ file_name: str @@ -145,7 +149,16 @@ class SlidesExportRequest(Base): widget_ids: list[str] | None = None visualization_ids: list[str] | None = None metadata: dict | None = None + template_id: str | None = None templateId: str | None = None + timezone_id: str | None = None + + def __attrs_post_init__(self) -> None: + if self.templateId is not None: + warn("templateId is deprecated, use template_id", DeprecationWarning, stacklevel=3) + if self.template_id is None: + self.template_id = self.templateId + self.templateId = None @staticmethod def client_class() -> type[SlidesExportRequestApi]: @@ -155,3 +168,28 @@ def client_class() -> type[SlidesExportRequestApi]: type[SlidesExportRequestApi]: SlidesExportRequestApi class """ return SlidesExportRequestApi + + +@define(kw_only=True) +class ImageExportRequest(Base): + """ + ImageExportRequest class is used to export dashboard widgets as images. + Attributes: + dashboard_id (str): Dashboard identifier. + file_name (str): File name of the exported image. + widget_ids (list[str]): Widgets to export. + format (str): Image format, PNG. + metadata (Optional[dict]): Free-form metadata of the request. + timezone_id (Optional[str]): Time zone the export evaluates dates in. + """ + + dashboard_id: str + file_name: str + widget_ids: list[str] + format: Literal["PNG"] = "PNG" + metadata: dict | None = None + timezone_id: str | None = None + + @staticmethod + def client_class() -> type[ImageExportRequestApi]: + return ImageExportRequestApi diff --git a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/declarative_model/workspace/automation.py b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/declarative_model/workspace/automation.py index 079fd90a8..e2c52c1bd 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/declarative_model/workspace/automation.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/declarative_model/workspace/automation.py @@ -3,7 +3,10 @@ from typing import Any from attrs import define, field +from gooddata_api_client.model.automation_external_recipient import AutomationExternalRecipient +from gooddata_api_client.model.automation_image_export import AutomationImageExport from gooddata_api_client.model.automation_schedule import AutomationSchedule +from gooddata_api_client.model.automation_slides_export import AutomationSlidesExport from gooddata_api_client.model.automation_tabular_export import AutomationTabularExport from gooddata_api_client.model.automation_visual_export import AutomationVisualExport from gooddata_api_client.model.declarative_automation import DeclarativeAutomation @@ -11,9 +14,12 @@ from gooddata_sdk.catalog.base import Base from gooddata_sdk.catalog.export.request import ( ExportRequest, + ImageExportRequest, + SlidesExportRequest, VisualExportRequest, ) from gooddata_sdk.catalog.identifier import ( + CatalogDeclarativeAnalyticalDashboardIdentifier, CatalogExportDefinitionIdentifier, CatalogNotificationChannelIdentifier, CatalogUserIdentifier, @@ -51,6 +57,33 @@ def client_class() -> builtins.type[AutomationVisualExport]: return AutomationVisualExport +@define(kw_only=True) +class CatalogAutomationImageExport(Base): + request_payload: ImageExportRequest + + @staticmethod + def client_class() -> builtins.type[AutomationImageExport]: + return AutomationImageExport + + +@define(kw_only=True) +class CatalogAutomationSlidesExport(Base): + request_payload: SlidesExportRequest + + @staticmethod + def client_class() -> builtins.type[AutomationSlidesExport]: + return AutomationSlidesExport + + +@define(kw_only=True) +class CatalogAutomationExternalRecipient(Base): + email: str + + @staticmethod + def client_class() -> builtins.type[AutomationExternalRecipient]: + return AutomationExternalRecipient + + @define(kw_only=True) class CatalogDeclarativeAutomation(CatalogAnalyticsBaseMeta): description: str | None = None @@ -65,6 +98,11 @@ class CatalogDeclarativeAutomation(CatalogAnalyticsBaseMeta): schedule: CatalogAutomationSchedule | None = None tabular_exports: list[CatalogAutomationTabularExport] | None = None visual_exports: list[CatalogAutomationVisualExport] | None = None + image_exports: list[CatalogAutomationImageExport] | None = None + slides_exports: list[CatalogAutomationSlidesExport] | None = None + external_recipients: list[CatalogAutomationExternalRecipient] | None = None + analytical_dashboard: CatalogDeclarativeAnalyticalDashboardIdentifier | None = None + evaluation_mode: str | None = None @staticmethod def client_class() -> builtins.type[DeclarativeAutomation]: diff --git a/packages/gooddata-sdk/tests/catalog/test_catalog_workspace.py b/packages/gooddata-sdk/tests/catalog/test_catalog_workspace.py index ba0277981..8c62129f1 100644 --- a/packages/gooddata-sdk/tests/catalog/test_catalog_workspace.py +++ b/packages/gooddata-sdk/tests/catalog/test_catalog_workspace.py @@ -6,6 +6,7 @@ from typing import Any from xml.etree import ElementTree as ET +import attrs import yaml from gooddata_sdk import ( BasicCredentials, @@ -1081,7 +1082,8 @@ def test_layout_automations(test_config): ] sdk.catalog_workspace.put_declarative_automations(workspace_id, automations_expected) automations_o = sdk.catalog_workspace.get_declarative_automations(workspace_id) - assert automations_expected == automations_o + # The server fills in the default evaluation mode. + assert [attrs.evolve(a, evaluation_mode="PER_RECIPIENT") for a in automations_expected] == automations_o finally: safe_delete(sdk.catalog_workspace.put_declarative_automations, workspace_id, []) safe_delete(sdk.catalog_organization.put_declarative_notification_channels, []) diff --git a/packages/gooddata-sdk/tests/catalog/unit_tests/test_declarative_automations.py b/packages/gooddata-sdk/tests/catalog/unit_tests/test_declarative_automations.py new file mode 100644 index 000000000..92e7691be --- /dev/null +++ b/packages/gooddata-sdk/tests/catalog/unit_tests/test_declarative_automations.py @@ -0,0 +1,63 @@ +# (C) 2026 GoodData Corporation +"""Unit test: automation fields survive the declarative round trip.""" + +from __future__ import annotations + +import pytest +from gooddata_sdk import CatalogDeclarativeAutomation, SlidesExportRequest + +_AUTOMATION = { + "id": "weekly-widgets", + "title": "Weekly widgets", + "evaluationMode": "PER_RECIPIENT", + "analyticalDashboard": {"id": "sales", "type": "analyticalDashboard"}, + "externalRecipients": [{"email": "someone@example.com"}], + "imageExports": [ + { + "requestPayload": { + "dashboardId": "sales", + "fileName": "revenue", + "format": "PNG", + "widgetIds": ["revenue-widget"], + "timezoneId": "Europe/Prague", + } + } + ], + "slidesExports": [ + { + "requestPayload": { + "dashboardId": "sales", + "fileName": "sales", + "format": "PPTX", + "templateId": "branded", + "widgetIds": ["revenue-widget"], + "timezoneId": "Europe/Prague", + } + } + ], +} + + +def test_automation_fields_survive_round_trip() -> None: + automation = CatalogDeclarativeAutomation.from_dict(_AUTOMATION) + + assert automation.evaluation_mode == "PER_RECIPIENT" + assert automation.analytical_dashboard is not None + assert automation.analytical_dashboard.id == "sales" + assert automation.external_recipients is not None + assert automation.external_recipients[0].email == "someone@example.com" + assert automation.image_exports is not None + assert automation.image_exports[0].request_payload.widget_ids == ["revenue-widget"] + assert automation.slides_exports is not None + assert automation.slides_exports[0].request_payload.timezone_id == "Europe/Prague" + assert automation.slides_exports[0].request_payload.template_id == "branded" + + assert automation.to_api().to_dict(camel_case=True) == _AUTOMATION + + +def test_slides_export_request_still_takes_template_id_in_camel_case() -> None: + with pytest.deprecated_call(): + request = SlidesExportRequest(file_name="sales", format="PDF", templateId="branded") + + assert request.template_id == "branded" + assert request.to_api().to_dict()["template_id"] == "branded" From 7c60ab7cb0d33155e71840987ebe63a07dba4ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Je=C5=A1ke?= Date: Thu, 26 Nov 2026 11:51:06 +0100 Subject: [PATCH 2/2] feat(gooddata-sdk): clone and deploy parameters as code `gdc clone` wrote no file for a parameter and `gdc deploy` sent none. Clone now writes each parameter to parameters/.yaml and deploy reads them back, like the other analytics objects. That covers textual, numeric and date range parameters (named periods). Needs the gooddata-code-convertors release that exposes the parameter converters (gooddata/gdc-ui#17383). jira: F1-3069 risk: low Co-Authored-By: Claude Opus 5.5 --- packages/gooddata-sdk/pyproject.toml | 2 +- .../src/gooddata_sdk/catalog/workspace/aac.py | 25 +++++++- .../catalog/unit_tests/test_aac_parameters.py | 58 +++++++++++++++++++ uv.lock | 6 +- 4 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 packages/gooddata-sdk/tests/catalog/unit_tests/test_aac_parameters.py diff --git a/packages/gooddata-sdk/pyproject.toml b/packages/gooddata-sdk/pyproject.toml index 39994727a..e6ff8746a 100644 --- a/packages/gooddata-sdk/pyproject.toml +++ b/packages/gooddata-sdk/pyproject.toml @@ -34,7 +34,7 @@ dependencies = [ "brotli==1.2.1", "requests>=2.33.0,<3.0.0", "python-dotenv>=1.2.2,<2.0.0", - "gooddata-code-convertors>=11.70.0a1", + "gooddata-code-convertors>=11.71.0a1", ] classifiers = [ "Development Status :: 5 - Production/Stable", diff --git a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/aac.py b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/aac.py index 2cc21cef1..39cf3b51c 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/aac.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/aac.py @@ -12,6 +12,7 @@ declarative_dataset_to_yaml, declarative_date_instance_to_yaml, declarative_metric_to_yaml, + declarative_parameter_to_yaml, declarative_plugin_to_yaml, declarative_publisher_document_template_to_yaml_v2, declarative_publisher_document_to_yaml_v2, @@ -22,6 +23,7 @@ yaml_dataset_to_declarative, yaml_date_dataset_to_declarative, yaml_metric_to_declarative, + yaml_parameter_to_declarative, yaml_plugin_to_declarative, yaml_publisher_document_template_to_declarative_v2, yaml_publisher_document_to_declarative_v2, @@ -70,6 +72,7 @@ "dashboard", "plugin", "attribute_hierarchy", + "parameter", "document", "document_template", "page_template", @@ -196,6 +199,11 @@ def aac_dashboard_to_declarative( return yaml_dashboard_to_declarative(ent, aac) +def aac_parameter_to_declarative(aac: dict[str, Any]) -> dict[str, Any]: + """Convert an AAC parameter dict to declarative format.""" + return yaml_parameter_to_declarative(aac) + + def aac_plugin_to_declarative(aac: dict[str, Any]) -> dict[str, Any]: """Convert an AAC plugin dict to declarative format.""" return yaml_plugin_to_declarative(aac) @@ -294,6 +302,11 @@ def declarative_dashboard_to_aac( return declarative_dashboard_to_yaml(ent, declarative) +def declarative_parameter_to_aac(declarative: dict[str, Any]) -> dict[str, Any]: + """Convert a declarative parameter dict to AAC format.""" + return declarative_parameter_to_yaml(declarative) + + def declarative_plugin_to_aac(declarative: dict[str, Any]) -> dict[str, Any]: """Convert a declarative plugin dict to AAC format.""" return declarative_plugin_to_yaml(declarative) @@ -359,6 +372,7 @@ def detect_yaml_format(path: Path) -> Literal["aac", "declarative"]: "dashboards", "plugins", "attributeHierarchies", + "parameters", "documents", "documentTemplates", "pageTemplates", @@ -436,6 +450,7 @@ def load_aac_workspace_from_disk( analytical_dashboards: list[dict[str, Any]] = [] dashboard_plugins: list[dict[str, Any]] = [] attribute_hierarchies: list[dict[str, Any]] = [] + parameters: list[dict[str, Any]] = [] documents: list[dict[str, Any]] = [] document_templates: list[dict[str, Any]] = [] page_templates: list[dict[str, Any]] = [] @@ -461,6 +476,8 @@ def load_aac_workspace_from_disk( dashboard_plugins.append(aac_plugin_to_declarative(aac)) case "attribute_hierarchy": attribute_hierarchies.append(aac_attribute_hierarchy_to_declarative(aac)) + case "parameter": + parameters.append(aac_parameter_to_declarative(aac)) case "document": documents.append(aac_document_to_declarative(aac)) case "document_template": @@ -491,6 +508,8 @@ def load_aac_workspace_from_disk( analytics["dashboardPlugins"] = dashboard_plugins if attribute_hierarchies: analytics["attributeHierarchyObjects"] = attribute_hierarchies + if parameters: + analytics["parameters"] = parameters if documents: analytics["documents"] = documents if document_templates: @@ -520,7 +539,7 @@ def store_aac_workspace_to_disk(model: CatalogDeclarativeWorkspaceModel, source_ """Convert a declarative workspace model to AAC YAML files and write to disk. Creates typed subdirectories (datasets/, metrics/, visualisations/, dashboards/, - plugins/, attributeHierarchies/, documents/, documentTemplates/, pageTemplates/) + plugins/, attributeHierarchies/, parameters/, documents/, documentTemplates/, pageTemplates/) under source_dir. Raises: @@ -568,6 +587,10 @@ def store_aac_workspace_to_disk(model: CatalogDeclarativeWorkspaceModel, source_ result = declarative_attribute_hierarchy_to_aac(hierarchy) _write_aac_file(source_dir, "attributeHierarchies", hierarchy["id"], result["content"]) + for parameter in analytics.get("parameters", []): + result = declarative_parameter_to_aac(parameter) + _write_aac_file(source_dir, "parameters", parameter["id"], result["content"]) + for document_id, result in documents: _write_aac_file(source_dir, "documents", document_id, result["content"]) diff --git a/packages/gooddata-sdk/tests/catalog/unit_tests/test_aac_parameters.py b/packages/gooddata-sdk/tests/catalog/unit_tests/test_aac_parameters.py new file mode 100644 index 000000000..524be9c9d --- /dev/null +++ b/packages/gooddata-sdk/tests/catalog/unit_tests/test_aac_parameters.py @@ -0,0 +1,58 @@ +# (C) 2026 GoodData Corporation +from __future__ import annotations + +from pathlib import Path +from typing import Any + +from gooddata_sdk.catalog.workspace.aac import load_aac_workspace_from_disk, store_aac_workspace_to_disk +from gooddata_sdk.catalog.workspace.declarative_model.workspace.workspace import CatalogDeclarativeWorkspaceModel +from gooddata_sdk.utils import read_layout_from_file + +_STRING = { + "id": "scenario", + "title": "Scenario", + "description": "Planning scenario", + "tags": ["planning"], + "content": {"type": "STRING", "defaultValue": "Actual"}, +} +_NUMBER = { + "id": "discount_rate", + "title": "Discount rate", + "description": "", + "tags": [], + "content": {"type": "NUMBER", "defaultValue": 0.5}, +} +_PERIOD = { + "id": "last_13_months", + "title": "Last 13 months", + "description": "", + "tags": [], + "content": {"type": "DATE_RANGE", "defaultValue": {"granularity": "MONTH", "from": "2024-11", "to": "2025-11"}}, +} +_OPEN_PERIOD = { + "id": "since_2024", + "title": "Since 2024", + "description": "", + "tags": [], + "content": {"type": "DATE_RANGE", "defaultValue": {"granularity": "YEAR", "from": "2024"}}, +} +_CODE_PARAMETERS = [_STRING, _NUMBER, _PERIOD, _OPEN_PERIOD] + + +def _model(parameters: list[dict[str, Any]]) -> CatalogDeclarativeWorkspaceModel: + return CatalogDeclarativeWorkspaceModel.from_dict({"analytics": {"parameters": parameters}}) + + +def _parameters(model: CatalogDeclarativeWorkspaceModel) -> list[dict[str, Any]]: + return model.to_dict(camel_case=True).get("analytics", {}).get("parameters", []) + + +def test_parameters_round_trip_through_aac(tmp_path: Path) -> None: + store_aac_workspace_to_disk(_model(_CODE_PARAMETERS), tmp_path) + + for parameter in _CODE_PARAMETERS: + stored = read_layout_from_file(tmp_path / "parameters" / f"{parameter['id']}.yaml") + assert stored["type"] == "parameter" + assert stored["definition"]["type"] == parameter["content"]["type"] + loaded = sorted(_parameters(load_aac_workspace_from_disk(tmp_path)), key=lambda p: p["id"]) + assert loaded == sorted(_CODE_PARAMETERS, key=lambda p: p["id"]) diff --git a/uv.lock b/uv.lock index 95862f222..b2643566b 100644 --- a/uv.lock +++ b/uv.lock @@ -1003,7 +1003,7 @@ requires-dist = [ [[package]] name = "gooddata-code-convertors" -version = "11.70.0a1" +version = "11.71.0a1" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "pydantic" }, @@ -1011,7 +1011,7 @@ dependencies = [ { name = "wasmtime" }, ] wheels = [ - { url = "https://files.pythonhosted.org/packages/d2/f2/d8a593112e36cded49941a95ac79bd0521ee1264081675239b3ed102f851/gooddata_code_convertors-11.70.0a1-py3-none-any.whl", hash = "sha256:0a61b2cee25dc07599000ed78a0b4162e052a0f5cb0d45b56dcd42deaea930a9", size = 1392118, upload-time = "2026-11-20T03:17:08.032Z" }, + { url = "https://files.pythonhosted.org/packages/2e/10/8e9df770e665b3f028c3afa3490ad0fd4272344550c6663e3e2e6c32485c/gooddata_code_convertors-11.71.0a1-py3-none-any.whl", hash = "sha256:ffa20b0ed320495ed556b979b6b8c842b65f059b129746772e3d8e4e181723f8", size = 1403099, upload-time = "2026-11-27T03:17:21.631Z" }, ] [[package]] @@ -1470,7 +1470,7 @@ requires-dist = [ { name = "brotli", specifier = "==1.2.1" }, { name = "cattrs", specifier = ">=22.1.0,<=26.1.0" }, { name = "gooddata-api-client", editable = "gooddata-api-client" }, - { name = "gooddata-code-convertors", specifier = ">=11.70.0a1" }, + { name = "gooddata-code-convertors", specifier = ">=11.71.0a1" }, { name = "pyarrow", marker = "extra == 'arrow'", specifier = ">=23.0.1" }, { name = "python-dateutil", specifier = ">=2.5.3" }, { name = "python-dotenv", specifier = ">=1.2.2,<2.0.0" },