@@ -1485,7 +1485,9 @@ def _set_value(self, entity, value):
1485
1485
if self ._repeated :
1486
1486
if not isinstance (value , (list , tuple , set , frozenset )):
1487
1487
raise exceptions .BadValueError (
1488
- "Expected list or tuple, got {!r}" .format (value )
1488
+ "In field {}, expected list or tuple, got {!r}" .format (
1489
+ self ._name , value
1490
+ )
1489
1491
)
1490
1492
value = [self ._do_validate (v ) for v in value ]
1491
1493
else :
@@ -2372,7 +2374,9 @@ def _validate(self, value):
2372
2374
.BadValueError: If ``value`` is not a :class:`bool`.
2373
2375
"""
2374
2376
if not isinstance (value , bool ):
2375
- raise exceptions .BadValueError ("Expected bool, got {!r}" .format (value ))
2377
+ raise exceptions .BadValueError (
2378
+ "In field {}, expected bool, got {!r}" .format (self ._name , value )
2379
+ )
2376
2380
return value
2377
2381
2378
2382
def _from_base_type (self , value ):
@@ -2417,7 +2421,9 @@ def _validate(self, value):
2417
2421
to one.
2418
2422
"""
2419
2423
if not isinstance (value , six .integer_types ):
2420
- raise exceptions .BadValueError ("Expected integer, got {!r}" .format (value ))
2424
+ raise exceptions .BadValueError (
2425
+ "In field {}, expected integer, got {!r}" .format (self ._name , value )
2426
+ )
2421
2427
return int (value )
2422
2428
2423
2429
@@ -2447,7 +2453,9 @@ def _validate(self, value):
2447
2453
to one.
2448
2454
"""
2449
2455
if not isinstance (value , six .integer_types + (float ,)):
2450
- raise exceptions .BadValueError ("Expected float, got {!r}" .format (value ))
2456
+ raise exceptions .BadValueError (
2457
+ "In field {}, expected float, got {!r}" .format (self ._name , value )
2458
+ )
2451
2459
return float (value )
2452
2460
2453
2461
@@ -2578,7 +2586,9 @@ def _validate(self, value):
2578
2586
exceeds the maximum length (1500 bytes).
2579
2587
"""
2580
2588
if not isinstance (value , bytes ):
2581
- raise exceptions .BadValueError ("Expected bytes, got {!r}" .format (value ))
2589
+ raise exceptions .BadValueError (
2590
+ "In field {}, expected bytes, got {!r}" .format (self ._name , value )
2591
+ )
2582
2592
2583
2593
if self ._indexed and len (value ) > _MAX_STRING_LENGTH :
2584
2594
raise exceptions .BadValueError (
@@ -2761,11 +2771,13 @@ def _validate(self, value):
2761
2771
value = value .decode ("utf-8" )
2762
2772
except UnicodeError :
2763
2773
raise exceptions .BadValueError (
2764
- "Expected valid UTF-8, got {!r}" .format (value )
2774
+ "In field {}, expected valid UTF-8, got {!r}" .format (
2775
+ self ._name , value
2776
+ )
2765
2777
)
2766
2778
else :
2767
2779
raise exceptions .BadValueError (
2768
- "Expected string, got {!r}" .format (value )
2780
+ "In field {}, expected string, got {!r}" .format (self . _name , value )
2769
2781
)
2770
2782
2771
2783
def _to_base_type (self , value ):
@@ -2920,7 +2932,9 @@ def _validate(self, value):
2920
2932
value = value .decode ("utf-8" )
2921
2933
except UnicodeError :
2922
2934
raise exceptions .BadValueError (
2923
- "Expected valid UTF-8, got {!r}" .format (value )
2935
+ "In field {}, expected valid UTF-8, got {!r}" .format (
2936
+ self ._name , value
2937
+ )
2924
2938
)
2925
2939
elif isinstance (value , six .string_types ):
2926
2940
encoded_length = len (value .encode ("utf-8" ))
@@ -3026,7 +3040,9 @@ def _validate(self, value):
3026
3040
.BadValueError: If ``value`` is not a :attr:`.GeoPt`.
3027
3041
"""
3028
3042
if not isinstance (value , GeoPt ):
3029
- raise exceptions .BadValueError ("Expected GeoPt, got {!r}" .format (value ))
3043
+ raise exceptions .BadValueError (
3044
+ "In field {}, expected GeoPt, got {!r}" .format (self ._name , value )
3045
+ )
3030
3046
3031
3047
3032
3048
class PickleProperty (BlobProperty ):
@@ -3447,7 +3463,9 @@ def _validate(self, value):
3447
3463
"""
3448
3464
# Might be GAE User or our own version
3449
3465
if type (value ).__name__ != "User" :
3450
- raise exceptions .BadValueError ("Expected User, got {!r}" .format (value ))
3466
+ raise exceptions .BadValueError (
3467
+ "In field {}, expected User, got {!r}" .format (self ._name , value )
3468
+ )
3451
3469
3452
3470
def _prepare_for_put (self , entity ):
3453
3471
"""Pre-put hook
@@ -3659,19 +3677,22 @@ def _validate(self, value):
3659
3677
and ``value`` does not match that kind.
3660
3678
"""
3661
3679
if not isinstance (value , Key ):
3662
- raise exceptions .BadValueError ("Expected Key, got {!r}" .format (value ))
3680
+ raise exceptions .BadValueError (
3681
+ "In field {}, expected Key, got {!r}" .format (self ._name , value )
3682
+ )
3663
3683
3664
3684
# Reject incomplete keys.
3665
3685
if not value .id ():
3666
3686
raise exceptions .BadValueError (
3667
- "Expected complete Key, got {!r}" .format (value )
3687
+ "In field {}, expected complete Key, got {!r}" .format (self . _name , value )
3668
3688
)
3669
3689
3670
3690
# Verify kind if provided.
3671
3691
if self ._kind is not None :
3672
3692
if value .kind () != self ._kind :
3673
3693
raise exceptions .BadValueError (
3674
- "Expected Key with kind={!r}, got " "{!r}" .format (self ._kind , value )
3694
+ "In field {}, expected Key with kind={!r}, got "
3695
+ "{!r}" .format (self ._name , self ._kind , value )
3675
3696
)
3676
3697
3677
3698
def _to_base_type (self , value ):
@@ -3722,7 +3743,9 @@ def _validate(self, value):
3722
3743
:class:`~google.cloud.ndb.model.BlobKey`.
3723
3744
"""
3724
3745
if not isinstance (value , BlobKey ):
3725
- raise exceptions .BadValueError ("Expected BlobKey, got {!r}" .format (value ))
3746
+ raise exceptions .BadValueError (
3747
+ "In field {}, expected BlobKey, got {!r}" .format (self ._name , value )
3748
+ )
3726
3749
3727
3750
3728
3751
class DateTimeProperty (Property ):
@@ -3838,7 +3861,9 @@ def _validate(self, value):
3838
3861
.BadValueError: If ``value`` is not a :class:`~datetime.datetime`.
3839
3862
"""
3840
3863
if not isinstance (value , datetime .datetime ):
3841
- raise exceptions .BadValueError ("Expected datetime, got {!r}" .format (value ))
3864
+ raise exceptions .BadValueError (
3865
+ "In field {}, expected datetime, got {!r}" .format (self ._name , value )
3866
+ )
3842
3867
3843
3868
if self ._tzinfo is None and value .tzinfo is not None :
3844
3869
raise exceptions .BadValueError (
@@ -3935,7 +3960,9 @@ def _validate(self, value):
3935
3960
.BadValueError: If ``value`` is not a :class:`~datetime.date`.
3936
3961
"""
3937
3962
if not isinstance (value , datetime .date ):
3938
- raise exceptions .BadValueError ("Expected date, got {!r}" .format (value ))
3963
+ raise exceptions .BadValueError (
3964
+ "In field {}, expected date, got {!r}" .format (self ._name , value )
3965
+ )
3939
3966
3940
3967
def _to_base_type (self , value ):
3941
3968
"""Convert a value to the "base" value type for this property.
@@ -3993,7 +4020,9 @@ def _validate(self, value):
3993
4020
.BadValueError: If ``value`` is not a :class:`~datetime.time`.
3994
4021
"""
3995
4022
if not isinstance (value , datetime .time ):
3996
- raise exceptions .BadValueError ("Expected time, got {!r}" .format (value ))
4023
+ raise exceptions .BadValueError (
4024
+ "In field {}, expected time, got {!r}" .format (self ._name , value )
4025
+ )
3997
4026
3998
4027
def _to_base_type (self , value ):
3999
4028
"""Convert a value to the "base" value type for this property.
@@ -4191,8 +4220,9 @@ def _validate(self, value):
4191
4220
return self ._model_class (** value )
4192
4221
if not isinstance (value , self ._model_class ):
4193
4222
raise exceptions .BadValueError (
4194
- "Expected %s instance, got %s"
4195
- % (self ._model_class .__name__ , value .__class__ )
4223
+ "In field {}, expected {} instance, got {!r}" .format (
4224
+ self ._name , self ._model_class .__name__ , value .__class__
4225
+ )
4196
4226
)
4197
4227
4198
4228
def _has_value (self , entity , rest = None ):
@@ -4399,7 +4429,9 @@ def _validate(self, value):
4399
4429
4400
4430
if not isinstance (value , self ._model_class ):
4401
4431
raise exceptions .BadValueError (
4402
- "Expected {}, got {!r}" .format (self ._model_class .__name__ , value )
4432
+ "In field {}, expected {}, got {!r}" .format (
4433
+ self ._name , self ._model_class .__name__ , value
4434
+ )
4403
4435
)
4404
4436
4405
4437
def _get_for_dict (self , entity ):
0 commit comments