Skip to content

Commit 6cef2dc

Browse files
authored
Merge branch 'main' into fix-12273-dict
2 parents 90b27a1 + 70bd6f9 commit 6cef2dc

File tree

8 files changed

+24
-21
lines changed

8 files changed

+24
-21
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ jobs:
249249

250250
# Run pytest with lax xfail because we often add tests to pydantic
251251
# which xfail on a pending release of pydantic-core
252-
- run: uv run pytest --override-ini=xfail_strict=False
252+
- run: uv run --no-sync pytest --override-ini=xfail_strict=False
253253
working-directory: pydantic
254254
env:
255255
PYDANTIC_PRIVATE_ALLOW_UNHANDLED_SCHEMA_TYPES: 1

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pydantic-core"
3-
version = "2.40.0"
3+
version = "2.40.1"
44
edition = "2021"
55
license = "MIT"
66
homepage = "https://github.com/pydantic/pydantic-core"

python/pydantic_core/core_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def context(self) -> ContextT:
145145
...
146146

147147
@property
148-
def mode(self) -> Literal['python', 'json']:
148+
def mode(self) -> Literal['python', 'json'] | str:
149149
"""The serialization mode set during serialization."""
150150
...
151151

src/serializers/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl PydanticSerializationUnexpectedValue {
195195
if let Some(field_name) = &self.field_name {
196196
write!(
197197
message,
198-
" [field_name={field_name}, input_value={value_str}, input_type={input_type}]"
198+
" [field_name='{field_name}', input_value={value_str}, input_type={input_type}]"
199199
)
200200
.expect("writing to string should never fail");
201201
} else {

src/validators/model.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,12 @@ impl ModelValidator {
300300
}
301301
}
302302

303-
let instance = create_class(self.class.bind(py))?;
303+
let instance;
304304

305305
if self.root_model {
306306
let state = &mut state.rebind_extra(|extra| extra.field_name = Some(PyString::new(py, ROOT_FIELD)));
307307
let output = self.validator.validate(py, input, state)?;
308+
instance = create_class(self.class.bind(py))?;
308309

309310
let fields_set = if input.as_python().is_some_and(|py_input| py_input.is(&self.undefined)) {
310311
PySet::empty(py)?
@@ -315,6 +316,7 @@ impl ModelValidator {
315316
force_setattr(py, &instance, intern!(py, ROOT_FIELD), output)?;
316317
} else {
317318
let output = self.validator.validate(py, input, state)?;
319+
instance = create_class(self.class.bind(py))?;
318320

319321
let (model_dict, model_extra, val_fields_set): (Bound<PyAny>, Bound<PyAny>, Bound<PyAny>) =
320322
output.extract(py)?;

tests/serializers/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def test_model_wrong_warn():
286286

287287
with pytest.warns(
288288
UserWarning,
289-
match=r"Expected `int` - serialized value may not be as expected \[field_name=foo, input_value='lorem', input_type=str\]",
289+
match=r"Expected `int` - serialized value may not be as expected \[field_name='foo', input_value='lorem', input_type=str\]",
290290
):
291291
assert s.to_python(BasicModel(foo='lorem')) == {'foo': 'lorem'}
292292

uv.lock

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)