semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

Python: Bug: Newly released Pydantic 2.9.0 breaks Semantic Kernel

Open brycecutt-msft opened this issue 2 years ago • 3 comments

Describe the bug Any use of Semantic Kernel with Pydantic 2.9.0 throws this error:

(... lots of other stuff ...)
File ~/.python/current/lib/python3.12/site-packages/pydantic/_internal/_discriminated_union.py:289, in _ApplyInferredDiscriminator._handle_choice(self, choice)
    [278]     self._choices_to_handle.extend(choices_schemas)
    [279] elif choice['type'] not in {
    [280]     'model',
    [281]     'typed-dict',
   (...)
    [287] } and not _core_utils.is_function_with_inner_schema(choice):
    [288]     # We should eventually handle 'definition-ref' as well
--> [289]     raise TypeError(
    [290]         f'{choice["type"]!r} is not a valid discriminated union variant;'
    [291]         ' should be a `BaseModel` or `dataclass`'
    [292]     )
    [293] else:
    [294]     if choice['type'] == 'tagged-union' and self._is_discriminator_shared(choice):
    [295]         # In this case, this inner tagged-union is compatible with the outer tagged-union,
    [296]         # and its choices can be coalesced into the outer TaggedUnionSchema.

TypeError: 'list' is not a valid discriminated union variant; should be a `BaseModel` or `dataclass`

To Reproduce Steps to reproduce the behavior:

  1. Check out main branch
  2. Open in dev container
  3. Open a sample such as: python/samples/getting_started/00-getting-started.ipynb
  4. Run first cell
  5. See error
  6. Install Pydantic 2.8.2 (previous release), restart notebook kernel (if needed), re-run first cell, and notice it now works without error

Expected behavior No error.

Screenshots image

Platform

  • OS: Linux inside the SK dev container (in WSL)
  • IDE: VS Code
  • Language: Python
  • Source: main branch of repository

Additional context None

brycecutt-msft avatar Sep 05 '24 20:09 brycecutt-msft

Hello @brycecutt-msft, I am unable to repro this. The entire 00 getting_started notebook works well.

image

Granted, I am running locally on MacOS and not in a dev container -- but it should be the same if running from main.

On a personal machine, I am running the latest SK Python 1.8.2 pip package, and I am not seeing any error either.

moonbox3 avatar Sep 06 '24 14:09 moonbox3

With that said, the issue is known on the Pydantic side, and a patch should be rolled out today. We will get a new package out as soon as we pull in their fix. https://github.com/pydantic/pydantic/issues/10326

moonbox3 avatar Sep 06 '24 16:09 moonbox3

Update: we've released SK Python 1.8.3 which contains the fix for this error.

moonbox3 avatar Sep 06 '24 18:09 moonbox3