-
|
Having a well described model and schema using Pydantic and Beanie syntax, there are some collections, represented by their Document classes, which are not been initialized by init_beanie function at the startup event of a Fastapi app. Did someone know what could be the causes of such a behavior? Fastapi-users set a very special class named User, which is one of the well initialized by the background Beanie engine. After that, I added my entire model which consists in several classes. For example, from my product_category module: From my product_subcategory module: ...and so. The outcome of init_beanie reflects an initialization of a collection named While a deeper debugging session through Beanie, I found where the exception So, according to this, there's a protected member named _document_settings which is None and it should be filled during the initialization step, meaning it should happen during the init_beanie call, am I right? That fragment code is at
, started at line 871. My virtual environment Fastapi_users' deployment contains this: At this point, I have to assume one of these things:
My guess? the first one. Issue here is I can't find what I'm doing wrong, or where. Any help, any clarification you can provide will be appreciated. Thanks in advance. I would appreciate any help you can provide. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
Hi! Can you please show the part of your code with the |
Beta Was this translation helpful? Give feedback.
-
|
Hi @roman-right .
I did And everything works fine. Maybe, Beanie can't follow relative paths, maybe there's a Pythonic-way to do this (to prefix some path in the relative ones, so Python inspection procedures can follow them, I really don't know), but simply putting the whole path was enough. |
Beta Was this translation helpful? Give feedback.
-
|
Is it possible to get a more detailed explanation of what happened here? I'm having the same issue, and have classes (BaseModels, Documents, UnionDoc) in separate modules. |
Beta Was this translation helpful? Give feedback.
Hi @roman-right .
Problem solved, my friend. Forget about the files I've already sent you. The key for solving this was given by you: ..."a one-file small example...", remember? I did it myself, and after fixing some module imports, everything works fine. Then, I got back to my project and conceptually, the biggest difference was the import clause: all relative paths were changed to absolute, meaning exactly what it is: class ProductCategory was in module product_category, when it was imported, the import clause looks like in the file (the file wasn't right, ok? But I've already told you to forget them). So, instead of
from .models.product_category import ProductCategoryI did