Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pydantic/pydantic
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.9.1
Choose a base ref
...
head repository: pydantic/pydantic
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.9.2
Choose a head ref
  • 7 commits
  • 14 files changed
  • 3 contributors

Commits on Sep 17, 2024

  1. Copy the full SHA
    8a0e7ad View commit details
  2. Copy the full SHA
    26cff3c View commit details
  3. Copy the full SHA
    fbfe25a View commit details
  4. Fix variance issue in _IncEx type alias, only allow True (#10414)

    Co-authored-by: sydney-runkle <sydneymarierunkle@gmail.com>
    Viicos and sydney-runkle committed Sep 17, 2024
    Copy the full SHA
    ea6115d View commit details
  5. Copy the full SHA
    c0a288f View commit details
  6. v bump

    sydney-runkle committed Sep 17, 2024
    Copy the full SHA
    7eab2b8 View commit details
  7. history updates

    sydney-runkle committed Sep 17, 2024
    Copy the full SHA
    7cedbfb View commit details
29 changes: 29 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
## v2.9.2 (2024-09-17)

[GitHub release](https://github.com/pydantic/pydantic/releases/tag/v2.9.2)

### What's Changed

#### Fixes
* Do not error when trying to evaluate annotations of private attributes by @Viicos in [#10358](https://github.com/pydantic/pydantic/pull/10358)
* Adding notes on designing sound `Callable` discriminators by @sydney-runkle in [#10400](https://github.com/pydantic/pydantic/pull/10400)
* Fix serialization schema generation when using `PlainValidator` by @Viicos in [#10427](https://github.com/pydantic/pydantic/pull/10427)
* Fix `Union` serialization warnings by @sydney-runkle in [pydantic/pydantic-core#1449](https://github.com/pydantic/pydantic-core/pull/1449)
* Fix variance issue in `_IncEx` type alias, only allow `True` by @Viicos in [#10414](https://github.com/pydantic/pydantic/pull/10414)
* Fix `ZoneInfo` validation with various invalid types by @sydney-runkle in [#10408](https://github.com/pydantic/pydantic/pull/10408)

## v2.9.1 (2024-09-09)

[GitHub release](https://github.com/pydantic/pydantic/releases/tag/v2.9.1)

### What's Changed

#### Fixes
* Fix Predicate issue in v2.9.0 by @sydney-runkle in [#10321](https://github.com/pydantic/pydantic/pull/10321)
* Fixing `annotated-types` bound to `>=0.6.0` by @sydney-runkle in [#10327](https://github.com/pydantic/pydantic/pull/10327)
* Turn `tzdata` install requirement into optional `timezone` dependency by @jakob-keller in [#10331](https://github.com/pydantic/pydantic/pull/10331)
* Fix `IncExc` type alias definition by @Viicos in [#10339](https://github.com/pydantic/pydantic/pull/10339)
* Use correct types namespace when building namedtuple core schemas by @Viicos in [#10337](https://github.com/pydantic/pydantic/pull/10337)
* Fix evaluation of stringified annotations during namespace inspection by @Viicos in [#10347](https://github.com/pydantic/pydantic/pull/10347)
* Fix tagged union serialization with alias generators by @sydney-runkle in [pydantic/pydantic-core#1442](https://github.com/pydantic/pydantic-core/pull/1442)

## v2.9.0 (2024-09-05)

[GitHub release](https://github.com/pydantic/pydantic/releases/tag/v2.9.0)
2 changes: 1 addition & 1 deletion docs/concepts/serialization.md
Original file line number Diff line number Diff line change
@@ -700,7 +700,7 @@ print(t.model_dump(include={'id': True, 'user': {'id'}}))
#> {'id': '1234567890', 'user': {'id': 42}}
```

The `True` indicates that we want to exclude or include an entire key, just as if we included it in a set.
Using `True` indicates that we want to exclude or include an entire key, just as if we included it in a set (note that using `False` isn't supported).
This can be done at any depth level.

Special care must be taken when including or excluding fields from a list or tuple of submodels or dictionaries.
13 changes: 13 additions & 0 deletions docs/concepts/unions.md
Original file line number Diff line number Diff line change
@@ -248,6 +248,19 @@ In the case of a `Union` with multiple models, sometimes there isn't a single un
across all models that you can use as a discriminator.
This is the perfect use case for a callable `Discriminator`.

!!! tip
When you're designing callable discriminators, remember that you might have to account
for both `dict` and model type inputs. This pattern is similar to that of `mode='before'` validators,
where you have to anticipate various forms of input.

But wait! You ask, I only anticipate passing in `dict` types, why do I need to account for models?
Pydantic uses callable discriminators for serialization as well, at which point the input to your callable is
very likely to be a model instance.

In the following examples, you'll see that the callable discriminators are designed to handle both `dict` and model inputs.
If you don't follow this practice, it's likely that you'll, in the best case, get warnings during serialization,
and in the worst case, get runtime errors during validation.

```py
from typing import Any, Literal, Union

Loading