Repl context question

I hope to execute some tasks or query data by importing models or jobs from the code through sanic REPL. However, by importing in this way, sanic is not actually run or ‘before_server_start’ is not executed because my mongo connection is placed under ‘before_server_start’.


from app.models.stuff import Stuff
row = await Stuff.find_one({id:1})

error: umongo.exceptions.NoDBDefinedError: db not set, please call set_db

async def mongodb_configure(app_inner, _loop):
    client_options = app_inner.config.get('MONGODB_CONNECT_OPTIONS', {})
    client = AsyncIOMotorClient(app_inner.config['MONGODB_URI'], **client_options)
    setattr(app_inner.ctx, self.app_attribute, client)
# models/
from bson import ObjectId
from umongo import Document, fields, validate, pre_load
from . import app, Base

class Stuff(Base):

There is no problem with starting through ‘sanic app.server:create_app’.