File tree Expand file tree Collapse file tree
src/PowerPlatform/Dataverse/operations Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121
2222
2323def _validate_guid (record_id : str , param_name : str = "record_id" ) -> None :
24- """Raise ValueError if *record_id* is not a valid GUID."""
24+ """Raise ValueError if *record_id* is not a valid GUID.
25+
26+ Catches all non-GUID inputs uniformly:
27+ * ``ValueError`` -- malformed hex string (``uuid.UUID("not-a-guid")``)
28+ * ``AttributeError`` -- input lacks ``replace``/``encode`` (rare)
29+ * ``TypeError`` -- non-string input such as ``None`` or ``int``
30+ (``uuid.UUID(None)`` / ``uuid.UUID(123)``). Without this, callers
31+ would see the raw constructor message ``"one of the hex, bytes, ...
32+ arguments must be given"`` instead of the helpful message below.
33+ """
2534 try :
2635 uuid .UUID (record_id )
27- except (ValueError , AttributeError ):
36+ except (ValueError , AttributeError , TypeError ):
2837 raise ValueError (
2938 f"{ param_name } { record_id !r} is not a valid GUID "
3039 f"(expected 8-4-4-4-12 hex, e.g. 'a1b2c3d4-1234-5678-9abc-def012345678'). "
Original file line number Diff line number Diff line change @@ -202,6 +202,20 @@ def test_valid_guid_accepted(self):
202202 result = self .client .records .retrieve ("account" , "a1b2c3d4-1234-5678-9abc-def012345678" )
203203 self .assertIsNotNone (result )
204204
205+ def test_retrieve_none_record_id_raises_value_error (self ):
206+ """retrieve(None) surfaces the friendly ValueError, not the raw uuid TypeError."""
207+ with self .assertRaises (ValueError ) as ctx :
208+ self .client .records .retrieve ("account" , None )
209+ self .assertIn ("not a valid GUID" , str (ctx .exception ))
210+ self .client ._odata ._get .assert_not_called ()
211+
212+ def test_retrieve_int_record_id_raises_value_error (self ):
213+ """retrieve(<int>) surfaces the friendly ValueError, not the raw uuid TypeError."""
214+ with self .assertRaises (ValueError ) as ctx :
215+ self .client .records .retrieve ("account" , 12345 )
216+ self .assertIn ("not a valid GUID" , str (ctx .exception ))
217+ self .client ._odata ._get .assert_not_called ()
218+
205219 # --------------------------------------------------------------------- get
206220
207221 def test_get_single (self ):
You can’t perform that action at this time.
0 commit comments