Skip to content

Commit 79eb871

Browse files
Update src/validators/uuid.rs
Co-authored-by: David Hewitt <[email protected]>
1 parent 932facb commit 79eb871

File tree

7 files changed

+10
-14
lines changed

7 files changed

+10
-14
lines changed

python/pydantic_core/core_schema.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3905,7 +3905,6 @@ def definition_reference_schema(
39053905
'url_too_long',
39063906
'url_scheme',
39073907
'uuid_type',
3908-
'uuid_exact_type',
39093908
'uuid_parsing',
39103909
'uuid_version_mismatch',
39113910
]

src/errors/types.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,6 @@ pub enum ErrorType {
310310
},
311311
// UUID errors,
312312
UuidType,
313-
UuidExactType {
314-
class_name: String,
315-
},
316313
UuidParsing {
317314
error: String,
318315
},
@@ -463,7 +460,6 @@ impl ErrorType {
463460
Self::UrlSyntaxViolation { .. } => extract_context!(Cow::Owned, UrlSyntaxViolation, ctx, error: String),
464461
Self::UrlTooLong { .. } => extract_context!(UrlTooLong, ctx, max_length: usize),
465462
Self::UrlScheme { .. } => extract_context!(UrlScheme, ctx, expected_schemes: String),
466-
Self::UuidExactType { .. } => extract_context!(UuidExactType, ctx, class_name: String),
467463
Self::UuidParsing { .. } => extract_context!(UuidParsing, ctx, error: String),
468464
Self::UuidVersionMismatch { .. } => {
469465
extract_context!(UuidVersionMismatch, ctx, version: usize, schema_version: usize)
@@ -572,7 +568,6 @@ impl ErrorType {
572568
Self::UrlSyntaxViolation {..} => "Input violated strict URL syntax rules, {error}",
573569
Self::UrlTooLong {..} => "URL should have at most {max_length} characters",
574570
Self::UrlScheme {..} => "URL scheme should be {expected_schemes}",
575-
Self::UuidExactType { .. } => "Input should be an instance of {class_name}",
576571
Self::UuidType => "UUID input should be a string, bytes or UUID object",
577572
Self::UuidParsing { .. } => "Input should be a valid UUID, {error}",
578573
Self::UuidVersionMismatch { .. } => "UUID version {version} does not match expected version: {schema_version}"
@@ -696,7 +691,6 @@ impl ErrorType {
696691
Self::UrlSyntaxViolation { error } => render!(tmpl, error),
697692
Self::UrlTooLong { max_length } => to_string_render!(tmpl, max_length),
698693
Self::UrlScheme { expected_schemes } => render!(tmpl, expected_schemes),
699-
Self::UuidExactType { class_name } => render!(tmpl, class_name),
700694
Self::UuidParsing { error } => render!(tmpl, error),
701695
Self::UuidVersionMismatch {
702696
version,
@@ -762,7 +756,6 @@ impl ErrorType {
762756
Self::UrlSyntaxViolation { error } => py_dict!(py, error),
763757
Self::UrlTooLong { max_length } => py_dict!(py, max_length),
764758
Self::UrlScheme { expected_schemes } => py_dict!(py, expected_schemes),
765-
Self::UuidExactType { class_name } => py_dict!(py, class_name),
766759

767760
Self::UuidParsing { error } => py_dict!(py, error),
768761
Self::UuidVersionMismatch {

src/serializers/shared.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ impl PyGcTraverse for CombinedSerializer {
255255
CombinedSerializer::Recursive(inner) => inner.py_gc_traverse(visit),
256256
CombinedSerializer::TuplePositional(inner) => inner.py_gc_traverse(visit),
257257
CombinedSerializer::TupleVariable(inner) => inner.py_gc_traverse(visit),
258+
CombinedSerializer::Uuid(inner) => inner.py_gc_traverse(visit),
258259
}
259260
}
260261
}

src/serializers/type_serializers/uuid.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub(crate) fn uuid_to_string(py_uuid: &PyAny) -> PyResult<String> {
1717
#[derive(Debug, Clone)]
1818
pub struct UuidSerializer;
1919

20+
impl_py_gc_traverse!(UuidSerializer {});
21+
2022
impl BuildSerializer for UuidSerializer {
2123
const EXPECTED_TYPE: &'static str = "uuid";
2224

src/validators/uuid.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ impl BuildValidator for UuidValidator {
8080
}
8181
}
8282

83+
impl_py_gc_traverse!(UuidValidator {});
84+
8385
impl Validator for UuidValidator {
8486
fn validate<'s, 'data>(
8587
&'s self,
@@ -107,8 +109,8 @@ impl Validator for UuidValidator {
107109
Ok(py_input.to_object(py))
108110
} else if extra.strict.unwrap_or(self.strict) && input.is_python() {
109111
Err(ValError::new(
110-
ErrorType::UuidExactType {
111-
class_name: self.get_name().to_string(),
112+
ErrorType::IsInstanceOf {
113+
class: class.name().unwrap_or("UUID").to_string(),
112114
},
113115
input,
114116
))

tests/test_errors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ def f(input_value, info):
282282
('url_syntax_violation', 'Input violated strict URL syntax rules, Foobar', {'error': 'Foobar'}),
283283
('url_too_long', 'URL should have at most 42 characters', {'max_length': 42}),
284284
('url_scheme', 'URL scheme should be "foo", "bar" or "spam"', {'expected_schemes': '"foo", "bar" or "spam"'}),
285-
('uuid_exact_type', 'Input should be an instance of Foobar', {'class_name': 'Foobar'}),
286285
('uuid_type', 'UUID input should be a string, bytes or UUID object', None),
287286
('uuid_parsing', 'Input should be a valid UUID, Foobar', {'error': 'Foobar'}),
288287
(

tests/validators/test_uuid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ def test_uuid(input_value, expected):
8989
'input_value,expected',
9090
[
9191
(UUID('12345678-1234-5678-1234-567812345678'), UUID('12345678-1234-5678-1234-567812345678')),
92-
('12345678-1234-5678-1234-567812345678', Err('Input should be an instance of uuid [type=uuid_exact_type,')),
93-
(b'12345678-1234-5678-1234-567812345678', Err('Input should be an instance of uuid [type=uuid_exact_type,')),
94-
(1654646400, Err('Input should be an instance of uuid [type=uuid_exact_type')),
92+
('12345678-1234-5678-1234-567812345678', Err('Input should be an instance of UUID [type=is_instance_of,')),
93+
(b'12345678-1234-5678-1234-567812345678', Err('Input should be an instance of UUID [type=is_instance_of,')),
94+
(1654646400, Err('Input should be an instance of UUID [type=is_instance_of')),
9595
],
9696
)
9797
def test_uuid_strict(input_value, expected):

0 commit comments

Comments
 (0)