Skip to content

Commit 7354135

Browse files
authored
Fix type mismatch error in property substitution (#4814)
1 parent 20fb3bb commit 7354135

File tree

6 files changed

+45
-2
lines changed

6 files changed

+45
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ BUG FIXES:
3434
* Fix missing metastoreDomains for Databricks, which caused metastore outages for some domains ([#4779](https://github.com/microsoft/AzureTRE/issues/4779))
3535
* Fix data exfiltration vulnerability in Azure ML workspace service by removing unrestricted AzureMachineLearning service tag access and enforcing RBAC-based storage access ([#4660](https://github.com/microsoft/AzureTRE/issues/4660))
3636
* Fix cost display duplication when user resource is deleted - UI incorrectly reused cost data for remaining resources ([#4783](https://github.com/microsoft/AzureTRE/issues/4783))
37+
* Fix type mismatch error where `{{ resource.parent.my_boolean_property }}` was returning string instead of the correct type ([#4813](https://github.com/microsoft/AzureTRE/issues/4813))
3738
* Delete npm package lock file ([#4810](https://github.com/microsoft/AzureTRE/issues/4810))
3839

3940
COMPONENTS:

api_app/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.25.12"
1+
__version__ = "0.25.13"

api_app/service_bus/substitutions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ def substitute_value(val: str, primary_resource_dict: dict, primary_parent_ws_di
151151
if isinstance(prop_to_get, dict) or isinstance(prop_to_get, list):
152152
return prop_to_get
153153
else:
154+
if val == "{{" + t + "}}":
155+
return prop_to_get
154156
val = val.replace("{{" + t + "}}", str(prop_to_get))
155157

156158
return val

api_app/tests_ma/test_service_bus/test_substitutions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,28 @@ def test_substitution_array_replace_not_found(
416416
obj = substitute_properties(step, primary_resource, None, None, resource_to_update)
417417
assert len(obj["rule_collections"]) == 1
418418
assert obj["rule_collections"][0]["name"] == "Object 1"
419+
420+
421+
def test_substitution_boolean_preservation(primary_resource):
422+
resource_dict = primary_resource.dict()
423+
# Mock a boolean property in the resource dict
424+
resource_dict["properties"]["isEnabled"] = True
425+
resource_dict["properties"]["count"] = 42
426+
427+
# Test boolean preservation
428+
val_to_sub = "{{ resource.properties.isEnabled }}"
429+
val = substitute_value(val_to_sub, resource_dict, None, None)
430+
assert val is True
431+
assert isinstance(val, bool)
432+
433+
# Test int preservation
434+
val_to_sub = "{{ resource.properties.count }}"
435+
val = substitute_value(val_to_sub, resource_dict, None, None)
436+
assert val == 42
437+
assert isinstance(val, int)
438+
439+
# Test string concatenation (should fallback to string)
440+
val_to_sub = "Count is {{ resource.properties.count }}"
441+
val = substitute_value(val_to_sub, resource_dict, None, None)
442+
assert val == "Count is 42"
443+
assert isinstance(val, str)

docs/tre-templates/pipeline-templates/pipeline-schema.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ It's possible to refer to properties from the primary resource (the resource tha
3131

3232
The syntax is `{{ resource.propertyName }}`. For example: `"{{ resource.properties.display_name }}"`.
3333

34+
### Accessing Parent Resource Properties
35+
It's also possible to access properties from the parent resources. This is useful when a resource needs information from its container (e.g. a user resource needing the workspace service's address space).
36+
37+
| Resource Type | Available References | Description |
38+
| --- | --- | --- |
39+
| User Resource | `{{ resource.parent.properties... }}` | Properties of the **Workspace Service** |
40+
| User Resource | `{{ resource.parent.parent.properties... }}` | Properties of the **Workspace** |
41+
| Workspace Service | `{{ resource.parent.properties... }}` | Properties of the **Workspace** |
42+
| Workspace | N/A | Workspaces do not have parents in this context |
43+
| Shared Service | N/A | Shared Services do not have parents in this context |
44+
3445
Example pipeline in `template_schema.json`:
3546
The below example references 2 properties from the primary resource to be used in updating the firewall shared service.
3647

docs/tre-workspace-authors/authoring-workspace-templates.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ All the values for the required parameters will be provided by the deployment ru
7676

7777
Any **custom parameters** are picked up by Azure TRE API and will be queried from the user deploying the workspace bundle. Custom parameters should also be defined in the `template_schema.json` file at the root of the bundle. This file follows the [JSON schema standard](http://json-schema.org/) and can be used by a user interface to generate a UI for the user to input the parameters.
7878

79+
### Template properties
80+
81+
When authoring a `template_schema.json` file, you can reference properties from the resource being deployed, or its parent resources. For more information see [Pipeline Template Schema](../tre-templates/pipeline-templates/pipeline-schema.md#substituting-resource-property-values).
82+
7983
### Output
8084

8185
!!! todo
@@ -109,7 +113,7 @@ The size of the `address_space` will default to `/24`, however other sizes can b
109113

110114
The `address_space` allocation will only take place during the install phase of a deployment, as this is a breaking change to your template you should increment the major version of your template, this means a you must deploy a new resource instead of upgrading an existing one.
111115

112-
In your install pipeline you also need to include a workspace upgrade step for the workspace to update it's `address_spaces` property.
116+
In your install and uninstall pipelines you also need to include a workspace upgrade step for the workspace to update it's `address_spaces` property.
113117

114118
```json
115119
"pipeline": {

0 commit comments

Comments
 (0)