@@ -196,6 +196,9 @@ error_types! {
196196 class_name: { ctx_type: String , ctx_fn: field_from_context} ,
197197 } ,
198198 // ---------------------
199+ // Default factory not called (happens when there's already an error and the factory takes data)
200+ DefaultFactoryNotCalled { } ,
201+ // ---------------------
199202 // None errors
200203 NoneRequired { } ,
201204 // ---------------------
@@ -480,6 +483,7 @@ impl ErrorType {
480483 }
481484
482485 pub fn message_template_python ( & self ) -> & ' static str {
486+ #[ allow( clippy:: match_same_arms) ] // much nicer to have the messages explicitly listed
483487 match self {
484488 Self :: NoSuchAttribute { ..} => "Object has no attribute '{attribute}'" ,
485489 Self :: JsonInvalid { ..} => "Invalid JSON: {error}" ,
@@ -496,6 +500,7 @@ impl ErrorType {
496500 Self :: ModelAttributesType { ..} => "Input should be a valid dictionary or object to extract fields from" ,
497501 Self :: DataclassType { ..} => "Input should be a dictionary or an instance of {class_name}" ,
498502 Self :: DataclassExactType { ..} => "Input should be an instance of {class_name}" ,
503+ Self :: DefaultFactoryNotCalled { ..} => "The default factory uses validated data, but at least one validation error occurred" ,
499504 Self :: NoneRequired { ..} => "Input should be None" ,
500505 Self :: GreaterThan { ..} => "Input should be greater than {gt}" ,
501506 Self :: GreaterThanEqual { ..} => "Input should be greater than or equal to {ge}" ,
@@ -637,12 +642,24 @@ impl ErrorType {
637642 } ;
638643 match self {
639644 Self :: NoSuchAttribute { attribute, .. } => render ! ( tmpl, attribute) ,
640- Self :: JsonInvalid { error, .. } => render ! ( tmpl, error) ,
645+ Self :: JsonInvalid { error, .. }
646+ | Self :: GetAttributeError { error, .. }
647+ | Self :: IterationError { error, .. }
648+ | Self :: DatetimeObjectInvalid { error, .. }
649+ | Self :: UrlParsing { error, .. }
650+ | Self :: UuidParsing { error, .. } => render ! ( tmpl, error) ,
651+ Self :: MappingType { error, .. }
652+ | Self :: DateParsing { error, .. }
653+ | Self :: DateFromDatetimeParsing { error, .. }
654+ | Self :: TimeParsing { error, .. }
655+ | Self :: DatetimeParsing { error, .. }
656+ | Self :: DatetimeFromDateParsing { error, .. }
657+ | Self :: TimeDeltaParsing { error, .. }
658+ | Self :: UrlSyntaxViolation { error, .. } => render ! ( tmpl, error) ,
641659 Self :: NeedsPythonObject { method_name, .. } => render ! ( tmpl, method_name) ,
642- Self :: GetAttributeError { error, .. } => render ! ( tmpl, error) ,
643- Self :: ModelType { class_name, .. } => render ! ( tmpl, class_name) ,
644- Self :: DataclassType { class_name, .. } => render ! ( tmpl, class_name) ,
645- Self :: DataclassExactType { class_name, .. } => render ! ( tmpl, class_name) ,
660+ Self :: ModelType { class_name, .. }
661+ | Self :: DataclassType { class_name, .. }
662+ | Self :: DataclassExactType { class_name, .. } => render ! ( tmpl, class_name) ,
646663 Self :: GreaterThan { gt, .. } => to_string_render ! ( tmpl, gt) ,
647664 Self :: GreaterThanEqual { ge, .. } => to_string_render ! ( tmpl, ge) ,
648665 Self :: LessThan { lt, .. } => to_string_render ! ( tmpl, lt) ,
@@ -667,26 +684,18 @@ impl ErrorType {
667684 let actual_length = actual_length. map_or ( Cow :: Borrowed ( "more" ) , |v| Cow :: Owned ( v. to_string ( ) ) ) ;
668685 to_string_render ! ( tmpl, field_type, max_length, actual_length, expected_plural, )
669686 }
670- Self :: IterationError { error, .. } => render ! ( tmpl, error) ,
671- Self :: StringTooShort { min_length, .. } => {
687+ Self :: StringTooShort { min_length, .. } | Self :: BytesTooShort { min_length, .. } => {
672688 let expected_plural = plural_s ( * min_length) ;
673689 to_string_render ! ( tmpl, min_length, expected_plural)
674690 }
675- Self :: StringTooLong { max_length, .. } => {
691+ Self :: StringTooLong { max_length, .. }
692+ | Self :: BytesTooLong { max_length, .. }
693+ | Self :: UrlTooLong { max_length, .. } => {
676694 let expected_plural = plural_s ( * max_length) ;
677695 to_string_render ! ( tmpl, max_length, expected_plural)
678696 }
679697 Self :: StringPatternMismatch { pattern, .. } => render ! ( tmpl, pattern) ,
680698 Self :: Enum { expected, .. } => to_string_render ! ( tmpl, expected) ,
681- Self :: MappingType { error, .. } => render ! ( tmpl, error) ,
682- Self :: BytesTooShort { min_length, .. } => {
683- let expected_plural = plural_s ( * min_length) ;
684- to_string_render ! ( tmpl, min_length, expected_plural)
685- }
686- Self :: BytesTooLong { max_length, .. } => {
687- let expected_plural = plural_s ( * max_length) ;
688- to_string_render ! ( tmpl, max_length, expected_plural)
689- }
690699 Self :: BytesInvalidEncoding {
691700 encoding,
692701 encoding_error,
@@ -710,33 +719,18 @@ impl ErrorType {
710719 ..
711720 } => PydanticCustomError :: format_message ( message_template, context. as_ref ( ) . map ( |c| c. bind ( py) ) ) ,
712721 Self :: LiteralError { expected, .. } => render ! ( tmpl, expected) ,
713- Self :: DateParsing { error, .. } => render ! ( tmpl, error) ,
714- Self :: DateFromDatetimeParsing { error, .. } => render ! ( tmpl, error) ,
715- Self :: TimeParsing { error, .. } => render ! ( tmpl, error) ,
716- Self :: DatetimeParsing { error, .. } => render ! ( tmpl, error) ,
717- Self :: DatetimeFromDateParsing { error, .. } => render ! ( tmpl, error) ,
718- Self :: DatetimeObjectInvalid { error, .. } => render ! ( tmpl, error) ,
719722 Self :: TimezoneOffset {
720723 tz_expected, tz_actual, ..
721724 } => to_string_render ! ( tmpl, tz_expected, tz_actual) ,
722- Self :: TimeDeltaParsing { error, .. } => render ! ( tmpl, error) ,
723- Self :: IsInstanceOf { class, .. } => render ! ( tmpl, class) ,
724- Self :: IsSubclassOf { class, .. } => render ! ( tmpl, class) ,
725+ Self :: IsInstanceOf { class, .. } | Self :: IsSubclassOf { class, .. } => render ! ( tmpl, class) ,
725726 Self :: UnionTagInvalid {
726727 discriminator,
727728 tag,
728729 expected_tags,
729730 ..
730731 } => render ! ( tmpl, discriminator, tag, expected_tags) ,
731732 Self :: UnionTagNotFound { discriminator, .. } => render ! ( tmpl, discriminator) ,
732- Self :: UrlParsing { error, .. } => render ! ( tmpl, error) ,
733- Self :: UrlSyntaxViolation { error, .. } => render ! ( tmpl, error) ,
734- Self :: UrlTooLong { max_length, .. } => {
735- let expected_plural = plural_s ( * max_length) ;
736- to_string_render ! ( tmpl, max_length, expected_plural)
737- }
738733 Self :: UrlScheme { expected_schemes, .. } => render ! ( tmpl, expected_schemes) ,
739- Self :: UuidParsing { error, .. } => render ! ( tmpl, error) ,
740734 Self :: UuidVersion { expected_version, .. } => to_string_render ! ( tmpl, expected_version) ,
741735 Self :: DecimalMaxDigits { max_digits, .. } => {
742736 let expected_plural = plural_s ( * max_digits) ;
0 commit comments