@@ -1581,8 +1581,20 @@ def _convert_labels_to_ints(self, table_schema_name: str, record: Dict[str, Any]
15811581 return resolved_record
15821582
15831583 def _attribute_payload (
1584- self , column_schema_name : str , dtype : Any , * , is_primary_name : bool = False
1584+ self ,
1585+ column_schema_name : str ,
1586+ dtype : Any ,
1587+ * ,
1588+ is_primary_name : bool = False ,
1589+ complex : bool = False ,
15851590 ) -> Optional [Dict [str , Any ]]:
1591+ """Build attribute metadata payload for a column.
1592+
1593+ :param complex: When ``True``, emit ``Complex*AttributeMetadata`` types
1594+ required by the ``CreateEntities`` action. When ``False`` (default),
1595+ emit the standard ``*AttributeMetadata`` types used by the
1596+ ``EntityDefinitions/{id}/Attributes`` endpoint.
1597+ """
15861598 # Enum-based local option set support
15871599 if isinstance (dtype , type ) and issubclass (dtype , Enum ):
15881600 return self ._enum_optionset_payload (column_schema_name , dtype , is_primary_name = is_primary_name )
@@ -1592,9 +1604,10 @@ def _attribute_payload(
15921604 )
15931605 dtype_l = dtype .lower ().strip ()
15941606 label = column_schema_name .split ("_" )[- 1 ]
1607+ prefix = "Microsoft.Dynamics.CRM.Complex" if complex else "Microsoft.Dynamics.CRM."
15951608 if dtype_l in ("string" , "text" ):
15961609 return {
1597- "@odata.type" : "Microsoft.Dynamics.CRM.ComplexStringAttributeMetadata " ,
1610+ "@odata.type" : f" { prefix } StringAttributeMetadata " ,
15981611 "SchemaName" : column_schema_name ,
15991612 "DisplayName" : self ._label (label ),
16001613 "RequiredLevel" : {"Value" : "None" },
@@ -1604,7 +1617,7 @@ def _attribute_payload(
16041617 }
16051618 if dtype_l in ("memo" , "multiline" ):
16061619 return {
1607- "@odata.type" : "Microsoft.Dynamics.CRM.ComplexMemoAttributeMetadata " ,
1620+ "@odata.type" : f" { prefix } MemoAttributeMetadata " ,
16081621 "SchemaName" : column_schema_name ,
16091622 "DisplayName" : self ._label (label ),
16101623 "RequiredLevel" : {"Value" : "None" },
@@ -1614,7 +1627,7 @@ def _attribute_payload(
16141627 }
16151628 if dtype_l in ("int" , "integer" ):
16161629 return {
1617- "@odata.type" : "Microsoft.Dynamics.CRM.ComplexIntegerAttributeMetadata " ,
1630+ "@odata.type" : f" { prefix } IntegerAttributeMetadata " ,
16181631 "SchemaName" : column_schema_name ,
16191632 "DisplayName" : self ._label (label ),
16201633 "RequiredLevel" : {"Value" : "None" },
@@ -1624,7 +1637,7 @@ def _attribute_payload(
16241637 }
16251638 if dtype_l in ("decimal" , "money" ):
16261639 return {
1627- "@odata.type" : "Microsoft.Dynamics.CRM.ComplexDecimalAttributeMetadata " ,
1640+ "@odata.type" : f" { prefix } DecimalAttributeMetadata " ,
16281641 "SchemaName" : column_schema_name ,
16291642 "DisplayName" : self ._label (label ),
16301643 "RequiredLevel" : {"Value" : "None" },
@@ -1634,7 +1647,7 @@ def _attribute_payload(
16341647 }
16351648 if dtype_l in ("float" , "double" ):
16361649 return {
1637- "@odata.type" : "Microsoft.Dynamics.CRM.ComplexDoubleAttributeMetadata " ,
1650+ "@odata.type" : f" { prefix } DoubleAttributeMetadata " ,
16381651 "SchemaName" : column_schema_name ,
16391652 "DisplayName" : self ._label (label ),
16401653 "RequiredLevel" : {"Value" : "None" },
@@ -1644,7 +1657,7 @@ def _attribute_payload(
16441657 }
16451658 if dtype_l in ("datetime" , "date" ):
16461659 return {
1647- "@odata.type" : "Microsoft.Dynamics.CRM.ComplexDateTimeAttributeMetadata " ,
1660+ "@odata.type" : f" { prefix } DateTimeAttributeMetadata " ,
16481661 "SchemaName" : column_schema_name ,
16491662 "DisplayName" : self ._label (label ),
16501663 "RequiredLevel" : {"Value" : "None" },
@@ -1653,12 +1666,12 @@ def _attribute_payload(
16531666 }
16541667 if dtype_l in ("bool" , "boolean" ):
16551668 return {
1656- "@odata.type" : "Microsoft.Dynamics.CRM.ComplexBooleanAttributeMetadata " ,
1669+ "@odata.type" : f" { prefix } BooleanAttributeMetadata " ,
16571670 "SchemaName" : column_schema_name ,
16581671 "DisplayName" : self ._label (label ),
16591672 "RequiredLevel" : {"Value" : "None" },
16601673 "OptionSet" : {
1661- "@odata.type" : "Microsoft.Dynamics.CRM.ComplexBooleanOptionSetMetadata " ,
1674+ "@odata.type" : f" { prefix } BooleanOptionSetMetadata " ,
16621675 "TrueOption" : {
16631676 "Value" : 1 ,
16641677 "Label" : self ._label ("True" ),
@@ -1672,7 +1685,7 @@ def _attribute_payload(
16721685 }
16731686 if dtype_l == "file" :
16741687 return {
1675- "@odata.type" : "Microsoft.Dynamics.CRM.ComplexFileAttributeMetadata " ,
1688+ "@odata.type" : f" { prefix } FileAttributeMetadata " ,
16761689 "SchemaName" : column_schema_name ,
16771690 "DisplayName" : self ._label (label ),
16781691 "RequiredLevel" : {"Value" : "None" },
@@ -1905,9 +1918,11 @@ def _create_table(
19051918 )
19061919
19071920 attributes : List [Dict [str , Any ]] = []
1908- attributes .append (self ._attribute_payload (primary_attr_schema , "string" , is_primary_name = True ))
1921+ attributes .append (
1922+ self ._attribute_payload (primary_attr_schema , "string" , is_primary_name = True , complex = True )
1923+ )
19091924 for col_name , dtype in schema .items ():
1910- payload = self ._attribute_payload (col_name , dtype )
1925+ payload = self ._attribute_payload (col_name , dtype , complex = True )
19111926 if not payload :
19121927 raise ValueError (f"Unsupported column type '{ dtype } ' for '{ col_name } '." )
19131928 attributes .append (payload )
0 commit comments