tortoise / tortoise/tortoise-orm
Confusing behaviour around 'apps'
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
A from the conversation between me and @FirstKlaas on Gitter:
- Example with
init.jsonwas confusing.because the name of the app is models as well as the expected key within the app is models. Maybe a best practise layout could help.What really confused me was the fact, that I could create an instance of a model "e.g. User.create(...)" without having it added to the constructor. No error popped up. I think a user feedback would be great, that I'm trying to use a model without having registered it.I could successfully define a model in a sub package, lets say petshop.pet. And without adding this module to the list of modules in the config.json file the corresponding table was created. The reason is, that main is in the modules array. Because of the Pet.create(...) statement in the same module, I have an import statement (from petshop import Pet). Now Pet is an attribute of main and therefore taken into account. If you put the import statement after the create_schemas() call, you get an ConfigurationError as expected.if you add two apps ("app1" and "app2") to the config file with the same modules, than the apps dict in Tortoise has to keys ("app1" and "app2"). Each has a dict width models. But the second dict is empty, because the implementation takes care, that a model can only be registered once. First come, first serve. No error occurs.
Potential outcomes:
- Document
appsconcept better. - Consider changing
appsconcept to allow multiple different instances of Tortoise ORM? - Add better error checking
- Add better error messages.
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 by reviewing the init.json and config.json examples and the apps and modules behavior around create_schemas(). Compare the reported model-registration, missing-registration, duplicate-app, and layout cases, then determine whether the outcome should document the apps concept, improve error messages, or change the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, databases
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100