Skip to content

Fix get_measure_dimension; add get/set for measure & time dimension (#1412)#1413

Merged
nicolasbisurgi merged 2 commits into
masterfrom
fix/measure-time-dimension-1412
Jun 10, 2026
Merged

Fix get_measure_dimension; add get/set for measure & time dimension (#1412)#1413
nicolasbisurgi merged 2 commits into
masterfrom
fix/measure-time-dimension-1412

Conversation

@nicolasbisurgi

@nicolasbisurgi nicolasbisurgi commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1412.

CubeService.get_measure_dimension returned the cube's last dimension, assuming the measures dimension is always last. That assumption does not hold — a cube's measures dimension can be assigned to any dimension — so the method could return the wrong dimension (confirmed live: plan_BudgetPlan's measures dimension is plan_business_unit, not its last dimension).

This PR reads the cube's MeasuresDimension navigation property instead, which reflects the actual assignment and is available on both v11 and v12. It also adds the matching time-dimension getter and setters for both.

Changes

  • get_measure_dimension — now reads /Cubes('x')/MeasuresDimension. When no measures dimension is explicitly assigned (server returns 204), falls back to the last dimension — TM1's own default — preserving prior behavior for that case.
  • get_time_dimension (new) — reads /Cubes('x')/TimeDimension; returns None when unassigned.
  • set_measure_dimension / set_time_dimension (new) — bind the navigation property via PATCH using @odata.bind. Decorated @require_data_admin and validate that the target dimension belongs to the cube (raising ValueError otherwise).
  • _validate_dimension_in_cube (new private helper).

Testing

5 new tests in Tests/CubeService_test.py (set+get round-trips for measure & time, the unset-time None case, and ValueError on invalid dimensions). Existing test_get_measure_dimension retained.

Verified live against both servers in Tests/config.ini:

  • v11 (tm1srv01, 11.8): 6/6 pass
  • v12 (tm1srv02, PA Engine): 6/6 pass

Black and Ruff pass on the changed files.

Note for reviewers

The v12 $metadata marks MeasuresDimension with @Core.Revisions: [{Version: 12.0.0, Kind: Deprecated}]. It is deprecated but currently functional on v12; flagging in case a different long-term endpoint is preferred.

get_measure_dimension previously returned the cube's last dimension, on
the assumption that the measures dimension is always last. That is not
guaranteed - a cube can have its measures dimension assigned to any
dimension - so the method could return the wrong dimension.

Read the cube's MeasuresDimension navigation property instead, which is
available on both v11 and v12 and reflects the actual assignment. When no
measures dimension is explicitly assigned, TM1 returns 204 and we fall
back to the last dimension (TM1's own default), preserving prior behavior
for that case.

Also add:
- get_time_dimension: reads the TimeDimension nav property (None if unset)
- set_measure_dimension / set_time_dimension: bind the nav property via
  PATCH, validating the dimension belongs to the cube first

Note: }CubeProperties (the v11 control cube) is not used, since it does
not exist on v12; the navigation-property approach works on both.

Tests added and verified live against v11 and v12.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nicolasbisurgi nicolasbisurgi self-assigned this Jun 4, 2026
@nicolasbisurgi nicolasbisurgi added the release:patch Triggers patch version bump (e.g.: 1.4.9 → 1.4.10) label Jun 4, 2026
@MariusWirtz

Copy link
Copy Markdown
Collaborator

I think we must add required_version decorators for these functions.

In version 11.8.01700.1 MeasuresDimension and TimeDimension properties are not listed as properties of the Cube in the $metadata XML.

The test_set_and_get_time_dimension fails in my environment with 11.8.01700.1. They do work on PAoC with 11.8.03500.6

The MeasuresDimension and TimeDimension navigation properties are not
exposed before v11.8.018 (confirmed: fails on 11.8.01700.1, works on
11.8.02200.2+). Add @require_version("11.8.018") to get/set_measure_dimension
and get/set_time_dimension so older servers raise a clear version error
instead of failing on the missing endpoint. Docstrings updated accordingly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nicolasbisurgi nicolasbisurgi merged commit ea0ad5b into master Jun 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:patch Triggers patch version bump (e.g.: 1.4.9 → 1.4.10)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_measure_dimension

2 participants