Skip to content

Combining string enums with generics results in stack overflow in Pydantic 1.8 #2436

Closed
@janheindejong

Description

@janheindejong

Checks

  • I added a descriptive title to this issue
    I have searched (google, github) for similar issues and couldn't find anything
    I have read and followed the docs and still think this is a bug

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.7.3
            pydantic compiled: True
                 install path: C:\Soft_Dev\LIVE_tls_application\back_end\.venv\Lib\site-packages\pydantic
               python version: 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]
                     platform: Windows-10-10.0.18362-SP0
     optional deps. installed: ['typing-extensions']

Love Pydantic, great stuff, etc etc.

I came across a bug in the following code (which works fine in 1.7.3) - the iteratively parsing of the model leads to stack overflow.

from pydantic import BaseModel
from pydantic.generics import GenericModel
from enum import Enum

from typing import TypeVar, Generic

class SomeStringEnum(str, Enum):
    A = "A"
    B = "B"


T = TypeVar("T")


class SomeGenericModel(GenericModel, Generic[T]):
    some_field: T


class MyModel(BaseModel):
    some_field: SomeGenericModel[SomeStringEnum]


print(MyModel.parse_obj({"some_field": {"some_field": "A"}}))

Activity

orfeldman-deci

orfeldman-deci commented on Mar 1, 2021

@orfeldman-deci

Hi we have the same use case and the last version broke our code,
I think this is a very common use case, maybe consider releasing a hotfix to pip?

samuelcolvin

samuelcolvin commented on Mar 1, 2021

@samuelcolvin
Member

We will release v1.8.1 in a day or two with a fix for this. You can help by checking all the PRs related to issues since v1.8.

added this to the v1.8.1 milestone on Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @samuelcolvin@janheindejong@orfeldman-deci

      Issue actions

        Combining string enums with generics results in stack overflow in Pydantic 1.8 · Issue #2436 · pydantic/pydantic