tortoise / tortoise/tortoise-orm
pydantic_model_creator can't see string references to other models.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Describe the bug
When a ReverseRelation field is referenced on a model, and its defined by passing in the name of that ReverseRelation, pydantic_model_creator doesn't recognise the model. The Signal() class should be in another file, ie, app.models.signal
To Reproduce
class Signal(Model):
foo='someting'
class User(Model):
signals: fields.ReverseRelation["Signal"]
UserOut_Pydantic = pydantic_model_creator(
User, name="UserOut", include=("username", "photo_url"))
NameError: name 'Signal' is not defined
Expected behavior
I expect that pydantic_model_creator should recognise my Signal model, and if it doesn't, there should be a work around for passing in string references to ReverseRelation fields.
Additional context
Add any other context about the problem here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the pydantic_model_creator entry point and trace how ReverseRelation annotations are resolved when the related model is given as a string reference. Reproduce the NameError with the Signal and User example, then add coverage for models defined in separate modules and confirm model creation succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100