Skip to content

Commit a0d740f

Browse files
committed
fix(gooddata-sdk): [AUTO] fix-agent attempt 2
1 parent 891b9b7 commit a0d740f

2 files changed

Lines changed: 43 additions & 31 deletions

File tree

packages/gooddata-sdk/src/gooddata_sdk/catalog/organization/entity_model/llm_provider.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,25 @@ def _anthropic_auth_from_api(data: dict[str, Any]) -> CatalogAnthropicAuth:
200200
raise ValueError(f"Unknown Anthropic auth type: {auth_type}")
201201

202202

203+
def _anthropic_config_to_camel_dict(config: CatalogAnthropicProviderConfig) -> dict[str, Any]:
204+
"""Convert CatalogAnthropicProviderConfig to a camelCase dict for direct _data_store injection.
205+
206+
The generated API client's JsonApiLlmProviderInAttributesProviderConfig oneOf does not yet
207+
include AnthropicProviderConfig. We bypass schema validation by storing the config as a
208+
plain camelCase dict in _data_store; model_to_dict(serialize=True) serialises it correctly.
209+
"""
210+
result: dict[str, Any] = {"type": config.type}
211+
if config.base_url is not None:
212+
result["baseUrl"] = config.base_url
213+
if config.auth is not None:
214+
auth = config.auth
215+
auth_dict: dict[str, Any] = {"type": auth.type}
216+
if isinstance(auth, CatalogAnthropicApiKeyAuth) and auth.api_key is not None:
217+
auth_dict["apiKey"] = auth.api_key
218+
result["auth"] = auth_dict
219+
return result
220+
221+
203222
def _provider_config_from_api(data: dict[str, Any]) -> CatalogLlmProviderConfig:
204223
provider_type = safeget(data, ["type"]) or "OPENAI"
205224
auth_data = safeget(data, ["auth"])
@@ -241,6 +260,30 @@ class CatalogLlmProviderDocument(Base):
241260
def client_class() -> type[JsonApiLlmProviderInDocument]:
242261
return JsonApiLlmProviderInDocument
243262

263+
def to_api(self) -> JsonApiLlmProviderInDocument:
264+
"""Build the API model with special handling for Anthropic provider config.
265+
266+
The generated API client's JsonApiLlmProviderInAttributesProviderConfig oneOf schema
267+
does not yet include AnthropicProviderConfig, so the normal Base.to_api() / from_dict()
268+
path raises ApiValueError for type='ANTHROPIC'. When the provider config is Anthropic,
269+
we build the document without providerConfig (it is optional in the API), then inject
270+
the config as a raw camelCase dict directly into _data_store to bypass schema validation.
271+
"""
272+
provider_config = (
273+
self.data.attributes.provider_config if self.data.attributes is not None else None
274+
)
275+
if isinstance(provider_config, CatalogAnthropicProviderConfig):
276+
snake_dict = self._get_snake_dict()
277+
# Remove provider_config to avoid the oneOf validation failure in the generated client
278+
snake_dict["data"]["attributes"].pop("provider_config", None)
279+
api_doc = self.client_class().from_dict(snake_dict, camel_case=False)
280+
# Inject provider_config directly as a raw camelCase dict, bypassing oneOf schema
281+
api_doc.data.attributes._data_store["provider_config"] = (
282+
_anthropic_config_to_camel_dict(provider_config)
283+
)
284+
return api_doc
285+
return super().to_api()
286+
244287

245288
@define(kw_only=True)
246289
class CatalogLlmProviderPatchDocument(Base):

packages/gooddata-sdk/tests/catalog/fixtures/organization/test_anthropic_llm_provider.yaml

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)