I have a virtual method field, and its associated function is defined inside a module.
That function imports another function defined in another module.
And that last function also imports another module.
The virtual method function works ok when I call it from a controller function.
However, if I call that method in the scheduler environment, I have the error "Cannot import module mercadopago"
The virtual method field is defined in db.py like this:
from virtual_methods import set_metodo_pago
db.define_table('sitios',
Field('nombre'),
Field.Method('set_metodo_pago', lambda row, metodo_pago: sitios_set_metodo_pago(row, metodo_pago)))
These are my modules:
modules/virtual_methods.py
modules/globals.py
modules/mercadopago.py
modules/scheduler_functions.py
in modules/virtual_methods.py
def set_metodo_pago(row, metodo_pago):
from globals import get_mercadopago_client
mp = get_mercadopago_client()
...
in modules/globals.py
def get_mercadopago_client():
import mercadopago
return MP.client()
...
in modules/scheduler_function.py
def instalar_nuevo_sitio(nombre):
db = current.db
sitio = db(db.sitios.nombre == nombre).select().first()
sitio.set_metodo_pago(metodopago='ticket') # this is the line that throws the error
However, the same line works ok if I call it from a controller/function.
What am I missing?