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’.

CLI:

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

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

# server.py
@app.listener('before_server_start')
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/stuff.py
from bson import ObjectId
from umongo import Document, fields, validate, pre_load
from . import app, Base

@app.ctx.lazy_umongo.register
class Stuff(Base):
    pass

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