fastapi-crudrouter
fastapi-crudrouter copied to clipboard
Not populating nested models [Tortoise]
I found an issue when Tortoise's PydanticModel is used, where the related models are not being populated. Due to Tortoise's async nature and Pydantic lack of asyncio support, some methods need to be called to populate models with nested submodels properly (related link).
I hacked a fix for this in my fork, so we can continue development in my company. I want to clean it up and make a PR when I have some free time, but it seems that there is quite an elaborate test setup. Could you give me some pointers? Maybe I should make a test case apart from the rest, and you could give me the right pointers later when everything is finished.
What do you think?
If you could clean it up and PR it would be great! I would be happy to give you some pointers and help you out.
One thing of note, line 14 on your fork needs to be eventually moved in to the try catch shown below. Otherwise, CRUDrouter will crash for those that do not have tortoise installed.
try:
from tortoise.models import Model
except ImportError:
Model: Any = None # type: ignore
tortoise_installed = False
else:
tortoise_installed = True
Hey @marcoaaguiar, have you done any progress on this issue? Thanks
I created several tests of this issue failing. I can PR the WIP, if someone wants to finish it, it would be nice. I haven't had a lot of free time lately.
@marcoaaguiar, that would be great. I have some issues related to this issue as well but right now I don't have a complete solution to it. If you create a PR with our current work, then we can try to find together the most suitable solution. Cheers
@fullonic #68, I opened a WIP PR with the tests and the code changes. Feel free to ask questions
This error is related to:
tortoise.exceptions.NoValuesFetched: No values were fetched for this relation, first use .fetch_related() ??
I'm having this error using related models. This library saved much time, but without it, I will need to make all by hand.
@fullonic , any news about it?
Thanks!!
Would be great to pull @marcoaaguiar idea
Hi @diegocgaona. I still didn't have time to update our changes to make it available. We patched a lot of stuff to fit our needs that is making it hard to make a PR. To fix your issue you can use the PR #68 branch.
We are no longer using Tortoise in our products, so I will continue with #68. Feel free to continue or close that PR.