Skip to content

Commit 15c75e4

Browse files
tpellissierclaude
andcommitted
Add attribute docstrings to cascade constants and replace hardcoded strings
Use attribute docstrings (""" after assignment) for cascade behavior constants so Pylance/Pyright surfaces descriptions in IDE hover tooltips. Replace all hardcoded cascade string literals with named constants in client.py and the relationships example. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 15856d4 commit 15c75e4

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

examples/advanced/relationships.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
LocalizedLabel,
2929
CascadeConfiguration,
3030
)
31+
from PowerPlatform.Dataverse.common.constants import (
32+
CASCADE_BEHAVIOR_NO_CASCADE,
33+
CASCADE_BEHAVIOR_REMOVE_LINK,
34+
)
3135

3236

3337
# Simple logging helper
@@ -216,9 +220,9 @@ def main():
216220
referencing_entity=emp_table["table_logical_name"],
217221
referenced_attribute=f"{dept_table['table_logical_name']}id",
218222
cascade_configuration=CascadeConfiguration(
219-
delete="RemoveLink", # When department is deleted, remove the link but keep employees
220-
assign="NoCascade",
221-
merge="NoCascade",
223+
delete=CASCADE_BEHAVIOR_REMOVE_LINK,
224+
assign=CASCADE_BEHAVIOR_NO_CASCADE,
225+
merge=CASCADE_BEHAVIOR_NO_CASCADE,
222226
),
223227
)
224228

@@ -255,7 +259,7 @@ def main():
255259
display_name="Manager",
256260
description="The employee's direct manager",
257261
required=False,
258-
cascade_delete="RemoveLink",
262+
cascade_delete=CASCADE_BEHAVIOR_REMOVE_LINK,
259263
)
260264
)
261265

src/PowerPlatform/Dataverse/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
LocalizedLabel,
2020
CascadeConfiguration,
2121
)
22+
from .common.constants import CASCADE_BEHAVIOR_REMOVE_LINK
2223

2324

2425
class DataverseClient:
@@ -760,7 +761,7 @@ def create_one_to_many_relationship(
760761
referencing_entity="new_employee", # Child table (the "many" side)
761762
referenced_attribute="new_departmentid",
762763
cascade_configuration=CascadeConfiguration(
763-
delete="RemoveLink", # When department deleted, unlink employees
764+
delete=CASCADE_BEHAVIOR_REMOVE_LINK,
764765
),
765766
)
766767
@@ -871,7 +872,7 @@ def create_lookup_field(
871872
display_name: Optional[str] = None,
872873
description: Optional[str] = None,
873874
required: bool = False,
874-
cascade_delete: str = "RemoveLink",
875+
cascade_delete: str = CASCADE_BEHAVIOR_REMOVE_LINK,
875876
solution: Optional[str] = None,
876877
language_code: int = 1033,
877878
) -> Dict[str, Any]:
@@ -915,7 +916,7 @@ def create_lookup_field(
915916
referenced_table="account",
916917
display_name="Account",
917918
required=True,
918-
cascade_delete="RemoveLink"
919+
cascade_delete=CASCADE_BEHAVIOR_REMOVE_LINK
919920
)
920921
921922
print(f"Created lookup: {result['lookup_schema_name']}")

src/PowerPlatform/Dataverse/common/constants.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@
1616
ODATA_TYPE_MANY_TO_MANY_RELATIONSHIP = "Microsoft.Dynamics.CRM.ManyToManyRelationshipMetadata"
1717

1818
# Cascade behavior values for relationship operations
19+
# See: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/configure-entity-relationship-cascading-behavior
20+
1921
CASCADE_BEHAVIOR_CASCADE = "Cascade"
22+
"""Apply the action to all referencing table records associated with the referenced table record."""
23+
2024
CASCADE_BEHAVIOR_NO_CASCADE = "NoCascade"
25+
"""Do not apply the action to any referencing table records associated with the referenced table record."""
26+
2127
CASCADE_BEHAVIOR_REMOVE_LINK = "RemoveLink"
28+
"""Remove the value of the referencing column for all referencing table records associated with the referenced table record."""
29+
2230
CASCADE_BEHAVIOR_RESTRICT = "Restrict"
31+
"""Prevent the action on the referenced table record if there are any referencing table records associated with it."""

0 commit comments

Comments
 (0)