88import warnings
99from typing import Any , Dict , Iterable , Iterator , List , Optional , Union , overload , TYPE_CHECKING
1010
11- from ..models .protocol import DataverseModel
1211from ..models .record import QueryResult , Record
1312from ..models .upsert import UpsertItem
1413
@@ -57,16 +56,10 @@ def create(self, table: str, data: Dict[str, Any]) -> str: ...
5756 @overload
5857 def create (self , table : str , data : List [Dict [str , Any ]]) -> List [str ]: ...
5958
60- @overload
61- def create (self , table_or_entity : DataverseModel , data : None = None ) -> str : ...
62-
63- @overload
64- def create (self , table_or_entity : List [DataverseModel ], data : None = None ) -> List [str ]: ...
65-
6659 def create (
6760 self ,
68- table_or_entity : Union [ str , DataverseModel , List [ DataverseModel ]] ,
69- data : Optional [ Union [Dict [str , Any ], List [Dict [str , Any ]]]] = None ,
61+ table : str ,
62+ data : Union [Dict [str , Any ], List [Dict [str , Any ]]],
7063 ) -> Union [str , List [str ]]:
7164 """Create one or more records in a Dataverse table.
7265
@@ -87,49 +80,19 @@ def create(
8780 :raises TypeError: If ``data`` is not a dict or list[dict].
8881
8982 Example:
90- Create a single record (dict form) ::
83+ Create a single record::
9184
9285 guid = client.records.create("account", {"name": "Contoso"})
9386 print(f"Created: {guid}")
9487
95- Create multiple records (dict form) ::
88+ Create multiple records::
9689
9790 guids = client.records.create("account", [
9891 {"name": "Contoso"},
9992 {"name": "Fabrikam"},
10093 ])
10194 print(f"Created {len(guids)} accounts")
102-
103- Create from a DataverseModel instance::
104-
105- guid = client.records.create(Account(name="Contoso"))
10695 """
107- # DataverseModel dispatch: list of entities
108- if isinstance (table_or_entity , list ) and table_or_entity and isinstance (table_or_entity [0 ], DataverseModel ):
109- entities = table_or_entity
110- table = entities [0 ].__entity_logical_name__
111- data_list = [e .to_dict () for e in entities ]
112- with self ._client ._scoped_odata () as od :
113- entity_set = od ._entity_set_from_schema_name (table )
114- ids = od ._create_multiple (entity_set , table , data_list )
115- if not isinstance (ids , list ) or not all (isinstance (x , str ) for x in ids ):
116- raise TypeError ("_create (multi) did not return list[str]" )
117- return ids
118-
119- # DataverseModel dispatch: single entity
120- if isinstance (table_or_entity , DataverseModel ):
121- entity = table_or_entity
122- table = entity .__entity_logical_name__
123- record_data = entity .to_dict ()
124- with self ._client ._scoped_odata () as od :
125- entity_set = od ._entity_set_from_schema_name (table )
126- rid = od ._create (entity_set , table , record_data )
127- if not isinstance (rid , str ):
128- raise TypeError ("_create (single) did not return GUID string" )
129- return rid
130-
131- # Existing str/dict path
132- table = table_or_entity # type: ignore[assignment]
13396 with self ._client ._scoped_odata () as od :
13497 entity_set = od ._entity_set_from_schema_name (table )
13598 if isinstance (data , dict ):
@@ -148,9 +111,9 @@ def create(
148111
149112 def update (
150113 self ,
151- table_or_entity : Union [ str , DataverseModel ] ,
152- ids : Optional [ Union [str , List [str ]]] = None ,
153- changes : Optional [ Union [Dict [str , Any ], List [Dict [str , Any ]]]] = None ,
114+ table : str ,
115+ ids : Union [str , List [str ]],
116+ changes : Union [Dict [str , Any ], List [Dict [str , Any ]]],
154117 ) -> None :
155118 """Update one or more records in a Dataverse table.
156119
@@ -191,28 +154,7 @@ def update(
191154 [{"name": "Name A"}, {"name": "Name B"}],
192155 )
193156
194- Update from a DataverseModel instance::
195-
196- client.records.update(Account(name="Contoso Updated"), account_id)
197157 """
198- # DataverseModel dispatch: entity provides table + changes
199- if isinstance (table_or_entity , DataverseModel ):
200- entity = table_or_entity
201- table = entity .__entity_logical_name__
202- record_data = entity .to_dict ()
203- if ids is None :
204- raise TypeError ("record_id must be provided when updating from a DataverseModel" )
205- with self ._client ._scoped_odata () as od :
206- if isinstance (ids , str ):
207- od ._update (table , ids , record_data )
208- return None
209- if isinstance (ids , list ):
210- od ._update_by_ids (table , ids , record_data )
211- return None
212- return None
213-
214- # Existing str/dict path
215- table : str = table_or_entity # type: ignore[assignment]
216158 with self ._client ._scoped_odata () as od :
217159 if isinstance (ids , str ):
218160 if not isinstance (changes , dict ):
0 commit comments