Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Сreating a child model causes a RecursionError exception #293

Closed
pydevd opened this Issue Nov 5, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@pydevd
Copy link

pydevd commented Nov 5, 2018

Bug

  • OS: Ubuntu 14.04
  • Python version import sys; print(sys.version): 3.6.7
  • Pydantic version import pydantic; print(pydantic.VERSION): 0.14

I'm expecting, that I can use a classic inheritance for dataclass models:

import pydantic.dataclasses

@pydantic.dataclasses.dataclass
class A:
    a: str = None

@pydantic.dataclasses.dataclass
class B(A):
    b: str = None

B(a='a', b='b')

But as a result I'm receiving this:

Traceback (most recent call last):
  File "/usr/local/pyenv/versions/3.6.7/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-9-10a7116ca691>", line 12, in <module>
    B(a='a', b='b')
  File "<string>", line 4, in __init__
  File "/usr/local/pyenv/versions/3.6.7/lib/python3.6/site-packages/pydantic/dataclasses.py", line 13, in post_init
    self.__post_init_original__()
  File "/usr/local/pyenv/versions/3.6.7/lib/python3.6/site-packages/pydantic/dataclasses.py", line 13, in post_init
    self.__post_init_original__()
  File "/usr/local/pyenv/versions/3.6.7/lib/python3.6/site-packages/pydantic/dataclasses.py", line 13, in post_init
    self.__post_init_original__()
  [Previous line repeated 952 more times]
  File "/usr/local/pyenv/versions/3.6.7/lib/python3.6/site-packages/pydantic/dataclasses.py", line 9, in post_init
    d = validate_model(self.__pydantic_model__, self.__dict__)
  File "/usr/local/pyenv/versions/3.6.7/lib/python3.6/site-packages/pydantic/main.py", line 484, in validate_model
    v_, errors_ = field.validate(value, values, loc=field.alias, cls=model.__class__)
  File "/usr/local/pyenv/versions/3.6.7/lib/python3.6/site-packages/pydantic/fields.py", line 303, in validate
    v, errors = self._validate_singleton(v, values, loc, cls)
  File "/usr/local/pyenv/versions/3.6.7/lib/python3.6/site-packages/pydantic/fields.py", line 406, in _validate_singleton
    return self._apply_validators(v, values, loc, cls, self.validators)
  File "/usr/local/pyenv/versions/3.6.7/lib/python3.6/site-packages/pydantic/fields.py", line 412, in _apply_validators
    v = validator(v)
  File "/usr/local/pyenv/versions/3.6.7/lib/python3.6/site-packages/pydantic/validators.py", line 23, in str_validator
    if isinstance(v, (str, NoneType)):
RecursionError: maximum recursion depth exceeded in __instancecheck__

This line below causes this problem:
https://github.com/samuelcolvin/pydantic/blob/master/pydantic/dataclasses.py#L13

UPD: defining __post_init__ in child model fixes the problem, but this is workaround.

import pydantic.dataclasses

@pydantic.dataclasses.dataclass
class A:
    a: str = None

@pydantic.dataclasses.dataclass
class B(A):
    b: str = None

    def __post_init__():
        pass

B(a='a', b='b')

@samuelcolvin samuelcolvin added the bug label Nov 15, 2018

@samuelcolvin

This comment has been minimized.

Copy link
Owner

samuelcolvin commented Nov 15, 2018

thanks for reporting, I'll try and fix soon.

samuelcolvin added a commit that referenced this issue Nov 15, 2018

@samuelcolvin samuelcolvin referenced this issue Nov 15, 2018

Merged

dataclass inheritance #299

3 of 3 tasks complete

samuelcolvin added a commit that referenced this issue Nov 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.