Skip to content
This repository was archived by the owner on Apr 11, 2026. It is now read-only.

Rename validation and serialization schema types to be unique#1629

Open
Viicos wants to merge 1 commit intomainfrom
unique-schema-types
Open

Rename validation and serialization schema types to be unique#1629
Viicos wants to merge 1 commit intomainfrom
unique-schema-types

Conversation

@Viicos
Copy link
Copy Markdown
Member

@Viicos Viicos commented Feb 7, 2025

validator- or serializer- is prepended, and the existing ones are deprecated.

Change Summary

Partly fixes pydantic/pydantic#11087.

Related issue number

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

`validator-` or `serializer-` is prepended, and the existing
ones are deprecated.
@Viicos Viicos force-pushed the unique-schema-types branch from e1c4af5 to ec4e4a1 Compare February 7, 2025 15:29
Copy link
Copy Markdown
Collaborator

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this, I wonder if we should not change validators, and just change the serialization ones to ser-function-plain etc?

That would still be good enough to make the functional split, without potentially causing a lot of churn in validation error messages.

Comment thread src/serializers/shared.rs
}
}

fn get_new_type(py: Python, type_: &str) -> PyResult<String> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid allocating:

Suggested change
fn get_new_type(py: Python, type_: &str) -> PyResult<String> {
fn get_new_type<'a>(py: Python, type_: &'a str) -> PyResult<&'a str> {

(and then drop the .to_owned() calls below)

Comment thread src/validators/mod.rs
};
}

fn get_new_type(py: Python, type_: &str) -> PyResult<String> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:

Suggested change
fn get_new_type(py: Python, type_: &str) -> PyResult<String> {
fn get_new_type<'a>(py: Python, type_: &'a str) -> PyResult<&'a str> {

Comment thread tests/test_errors.py

assert str(exc_info.value) == (
'1 validation error for function-plain[my_function()]\n'
'1 validation error for validator-function-plain[my_function()]\n'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should just double-check we're happy with this new format, as it's potentially breaking to downstream test suites and if we change this we should aim to do so once and not again?

(e.g. would it be better if this just read 1 validation error for my_function()?)

Comment on lines +313 to +318
if schema['type'] not in {
'validator-function-before',
'validator-function-after',
'validator-function-wrap',
'validator-function-plain',
}:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exclusion is because these types are no longer supported in serialization, because of the split?

Do we need a similar test for serialization schemas?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make sure core schema types are unique

2 participants