Same model returned by pydantic_model_creator calls with different arguments #1741
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: