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

fix: nested ORM from nested dictionaries #3182

Merged
merged 1 commit into from Dec 19, 2021

Conversation

PrettyWood
Copy link
Member

Change Summary

Related issue number

closes #3181

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

class Getter(GetterDict):
# try to read the modified property name
# either as an attribute or as a key
def get(self, key, default):
key = key + key
try:
return self._obj[key]
v = self._obj[key]
return Getter(v) if isinstance(v, dict) else v
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nuno-andre Would it make sense to you?

@pboers1988
Copy link

Good catch! Noticed this one too on master

@kbakk
Copy link

kbakk commented Oct 12, 2021

Came across this issue with a similar case to the existing test, but slightly different:

from typing import List, Optional
from pydantic import BaseModel

class User(BaseModel):
    name: str
    value: Optional[str] = None
    class Config:
        orm_mode = True

class UserList(BaseModel):
    __root__: List[User]

UserList(__root__=[{"name": "aa", "value": "123"}])

Maybe it can be added as a test case.

Same as with #3181; it used to work but doesn't on master.

@PrettyWood
Copy link
Member Author

Please review

@PrettyWood PrettyWood mentioned this pull request Dec 19, 2021
4 tasks
@samuelcolvin samuelcolvin merged commit 93faefb into pydantic:master Dec 19, 2021
@PrettyWood PrettyWood deleted the fix/nested-orm branch December 19, 2021 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested ORM-mode models can no longer be initialized from nested dictionaries
4 participants