Skip to content

Commit b3a071f

Browse files
committed
fix(sdk): support ui identifier ref conversion
Conversion logic adjusted to follow ui-sdk counterpart. Hence somewhat chaotic usage of defaultType values in some cases. risk: low JIRA: CQ-1080
1 parent b1e24a7 commit b3a071f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

gooddata-sdk/gooddata_sdk/utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from enum import Enum, auto
1010
from pathlib import Path
1111
from shutil import rmtree
12-
from typing import Any, Callable, NamedTuple, Union, cast, no_type_check
12+
from typing import Any, Callable, NamedTuple, Optional, Union, cast, no_type_check
1313
from warnings import warn
1414
from xml.etree import ElementTree as ET
1515

@@ -396,28 +396,33 @@ def read_json(path: Union[str, Path]) -> Any:
396396
return json.loads(f.read())
397397

398398

399-
def ref_extract_obj_id(ref: dict[str, Any]) -> ObjId:
399+
def ref_extract_obj_id(ref: dict[str, Any], type: Optional[str] = None) -> ObjId:
400400
"""
401401
Extracts ObjId from a ref dictionary.
402402
:param ref: the ref to extract from
403+
:param type: the type of the object to fall back to in case of string identifier
403404
:return: the extracted ObjId
404405
:raises ValueError: if the ref is not an identifier
405406
"""
406407
if "identifier" in ref:
408+
if isinstance(ref["identifier"], str):
409+
if not type:
410+
raise ValueError("identifier is a string, but fallback type is not provided")
411+
return ObjId(id=ref["identifier"], type=type)
407412
return ObjId(id=ref["identifier"]["id"], type=ref["identifier"]["type"])
408413

409414
raise ValueError("invalid ref. must be identifier")
410415

411416

412-
def ref_extract(ref: dict[str, Any]) -> Union[str, ObjId]:
417+
def ref_extract(ref: dict[str, Any], type: Optional[str] = None) -> Union[str, ObjId]:
413418
"""
414419
Extracts an object id from a ref dictionary: either an identifier or a localIdentifier.
415420
:param ref: the ref to extract from
416421
:return: thr extracted object id
417422
:raises ValueError: if the ref is not an identifier or localIdentifier
418423
"""
419424
try:
420-
return ref_extract_obj_id(ref)
425+
return ref_extract_obj_id(ref, type)
421426
except ValueError:
422427
pass
423428

gooddata-sdk/gooddata_sdk/visualization.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,11 @@ def show_all_values(self) -> Optional[bool]:
394394
return self._a.get("showAllValues")
395395

396396
def as_computable(self) -> Attribute:
397-
return Attribute(local_id=self.local_id, label=ref_extract(self.label), show_all_values=self.show_all_values)
397+
return Attribute(
398+
local_id=self.local_id,
399+
label=ref_extract(self.label), # , "label"),
400+
show_all_values=self.show_all_values,
401+
)
398402

399403
def __str__(self) -> str:
400404
return self.__repr__()

0 commit comments

Comments
 (0)