-
-
Notifications
You must be signed in to change notification settings - Fork 392
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
Same model returned by pydantic_model_creator calls with different arguments #1741
Same model returned by pydantic_model_creator calls with different arguments #1741
Conversation
Hey @waketzheng @waketzheng, any chance you can review this PR? Please let me know if more information or more tests are required! Thanks! |
Pull Request Test Coverage Report for Build 11407291191Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for venturing into pydantic model created, it's one of more convoluted pieces of code there :)
Thank you for maintaining tortoise-orm! I'm glad to be of help! There was a PR (#735) a while ago that was partially solving the issue but never got merged, I think it can be closed now. |
* naming is not working * naming and description * naming is not working * naming and description * include improvements from #1741 * remove print statements * i should learn git better... * type hints, recursion protector, naming, .... should be ready for review * unused import statements... * test_early_init.py: naming of $defs changed * move dataclasses to a dedicated place * python 3.8 and 3.9: typing * test computed fields, remove own PydanticMeta class * remove print statements from tests * re-add pydantic_model_creator docstring it got lost during refactoring * remove _stack from pydantic_model_creator this is now handled by PydanticModelCreator * make some methods private * slim down dataclasses to only include necessary information * remove unused imports, satisfy mypy * add type annotation for ``from_pydantic_meta`` * better indexing of pydantic models * remove dataclasses for field descriptions pydantic_model_creator now accesses the fields directly * remove forgotten line of #1465 * include optional in hashed value * move dataclasses.py to descriptions.py * stupid unused import. * formatting
Description
This PR fixes the issue where calling
pydantic_model_creator
multiple times with different arguments without specifying a name might return the same model due to caching (_MODEL_INDEX
increator.py
). The example below demonstrates the issue.This issues affects the models that have no backward or forward reference to any other model.
This PR:
pydantic_model_creator
to create verbatim names for "root" models even if they do not have relationsexclude_readonly
to the hash used for naming unnamed models sopydantic_model_creator(People)
andpydantic_model_creator(People, exclude_readonly=True)
Motivation and Context
The issues that will be fixed by this PR:
pydantic_model_creator
without specify name #647There was an attempt to solve this issue previously but it was never merged. The approach used does not seem to work anymore.
How Has This Been Tested?
Checklist: