Closed henadzit closed 1 month ago
Hey @waketzheng @waketzheng, any chance you can review this PR? Please let me know if more information or more tests are required! Thanks!
Totals | |
---|---|
Change from base Build 11323175489: | 0.008% |
Covered Lines: | 5980 |
Relevant Lines: | 6603 |
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 (https://github.com/tortoise/tortoise-orm/pull/735) a while ago that was partially solving the issue but never got merged, I think it can be closed now.
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:
There 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: