zmievsa / pydantic-duality

Automatically and lazily generate three versions of your pydantic models: one with Extra.forbid, one with Extra.ignore, and one with all fields optional
https://ovsyanka83.github.io/pydantic-duality/
MIT License
32 stars 1 forks source link

After update to 1.2.3: RecursionError: maximum recursion depth exceeded #21

Closed peterschmidt85 closed 1 month ago

peterschmidt85 commented 1 month ago

With previous versions, everything is fine.

With 1.2.3, we got the following:

venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:136: in __new__
    new_class._generate_alternative_classes(
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:169: in _generate_alternative_classes
    _alter_attrs(attrs, name + request_suffix, REQUEST_ATTR),
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:71: in _alter_attrs
    annotations[key] = _resolve_annotation(val, attr)
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:54: in _resolve_annotation
    if inspect.isclass(annotation) and issubclass(annotation, BaseModel):
<frozen abc>:123: in __subclasscheck__
    ???
<frozen abc>:123: in __subclasscheck__
    ???
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:220: in __subclasscheck__
    return type.__subclasscheck__(cls, subclass) or issubclass(subclass, (cls.__request__, cls.__response__, cls.__patch_request__))
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:199: in __getattribute__
    return getattr(type.__getattribute__(self, REQUEST_ATTR), attr)
venv/lib/python3.11/site-packages/cached_classproperty/__init__.py:120: in __get__
    val = self.func(owner)
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:86: in constructor_wrapper
    obj = constructor()
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:177: in <lambda>
    tuple(_resolve_annotation(b, RESPONSE_ATTR) for b in bases),
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:177: in <genexpr>
    tuple(_resolve_annotation(b, RESPONSE_ATTR) for b in bases),
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:43: in _resolve_annotation
    return getattr(annotation, attr)
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:199: in __getattribute__
    return getattr(type.__getattribute__(self, REQUEST_ATTR), attr)
venv/lib/python3.11/site-packages/cached_classproperty/__init__.py:120: in __get__
    val = self.func(owner)
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:86: in constructor_wrapper
    obj = constructor()
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:178: in <lambda>
    _alter_attrs(attrs, name + response_suffix, RESPONSE_ATTR),
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:71: in _alter_attrs
    annotations[key] = _resolve_annotation(val, attr)
venv/lib/python3.11/site-packages/pydantic_duality/__init__.py:54: in _resolve_annotation
    if inspect.isclass(annotation) and issubclass(annotation, BaseModel):
<frozen abc>:123: in __subclasscheck__
    ???
E   RecursionError: maximum recursion depth exceeded
!!! Recursion detected (same locals & position)
=========================================================== short test summary info ============================================================
ERROR  - RecursionError: maximum recursion depth exc

More details in https://github.com/dstackai/dstack/actions/runs/11539562439/job/32119396209

zmievsa commented 1 month ago

Will fix right now.

zmievsa commented 1 month ago

Funny finding: if you reverse GCPConfigurator and AzureConfigurator imports -- it will actually stop going into infinite recursion. Still digging the why though :)

image
zmievsa commented 1 month ago

Fixed in 1.2.4