@@ -240,18 +240,19 @@ def _prepare_tabular_definition(
240240 return ExecutionDefinition (attributes = attributes , metrics = metrics , filters = filters , dimensions = dims )
241241
242242
243- def _as_table (response : ExecutionResponse ) -> ExecutionTable :
243+ def _as_table (response : ExecutionResponse , always_two_dimensional : bool = False ) -> ExecutionTable :
244244 first_page_offset = [0 , 0 ]
245245 first_page_limit = [_TABLE_ROW_BATCH_SIZE , _MAX_METRICS ]
246246
247- if not response .exec_def .has_attributes ():
248- # there are no attributes, there shall be at most one row with the metrics, so get that as first page
249- first_page_limit = [first_page_limit [1 ]]
250- first_page_offset = [0 ]
251- elif not response .exec_def .has_metrics ():
252- # there are no metrics; there may be many attribute headers
253- first_page_limit = [first_page_limit [0 ]]
254- first_page_offset = [0 ]
247+ if not always_two_dimensional :
248+ if not response .exec_def .has_attributes ():
249+ # there are no attributes, there shall be at most one row with the metrics, so get that as first page
250+ first_page_limit = [first_page_limit [1 ]]
251+ first_page_offset = [0 ]
252+ elif not response .exec_def .has_metrics ():
253+ # there are no metrics; there may be many attribute headers
254+ first_page_limit = [first_page_limit [0 ]]
255+ first_page_offset = [0 ]
255256
256257 first_page = response .read_result (offset = first_page_offset , limit = first_page_limit )
257258
@@ -771,18 +772,23 @@ class TableService:
771772 def __init__ (self , api_client : GoodDataApiClient ) -> None :
772773 self ._compute = ComputeService (api_client )
773774
774- def for_visualization (self , workspace_id : str , visualization : Visualization ) -> ExecutionTable :
775+ def for_visualization (
776+ self , workspace_id : str , visualization : Visualization , always_two_dimensional : bool = False
777+ ) -> ExecutionTable :
775778 # Assume the received visualization is a pivot table if:
776779 # - we can parse out "table" suffix from the attributes.contents.visualizationUrl
777780 # or
778781 # - it contains row ("attribute") bucket
782+
783+ # use always_two_dimensional to ignore special handling of cases where the visualization
784+ # to be executed should contain only metrics and no attributes or vice-versa.
779785 exec_def = (
780786 _get_exec_for_pivot (visualization )
781787 if _vis_is_table (visualization ) or visualization .has_bucket_of_type (BucketType .ROWS )
782788 else get_exec_for_non_pivot (visualization )
783789 )
784790 response = self ._compute .for_exec_def (workspace_id = workspace_id , exec_def = exec_def )
785- return _as_table (response )
791+ return _as_table (response , always_two_dimensional )
786792
787793 def for_items (
788794 self , workspace_id : str , items : list [Union [Attribute , Metric ]], filters : Optional [list [Filter ]] = None
0 commit comments