Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename validation and serialization schema types to be unique #1629

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Viicos
Copy link
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
Contributor

@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.

@@ -148,6 +149,29 @@ combined_serializer! {
}
}

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

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)

@@ -510,6 +511,30 @@ macro_rules! validator_match {
};
}

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

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> {

@@ -93,7 +93,7 @@ def my_function(input_value, info):
v.validate_python(42)

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
Contributor

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
Contributor

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 join this conversation on GitHub. Already have an account? Sign in to comment
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