I've "fixed" the problem, but I don't understand exactly what was it.
The problem wasn't the import itself, but the moment in wich I was doing it. Let's go back to the function that had the error, here with more detail def instalar_nuevo_sitio(nombre): sitio = db(db.sitios.nombre == nombre).select().first() # here it does a lot of stuff sitio.set_metodo_pago(metodopago='ticket') # this line throws the error Notice the comment where I say that in that place, the function does "a lot of stuff". What is that stuff? Well, what the function does is to install a new app in web2py, that is, clonning the repository and putting all the files needed by the new app. How did I solve it? I just moved the sentence to the top, before doing that "lot of stuff". I don't know why exactly that worked, because the line that throwed the error doesn't have anything to do with the new application installed by the function. Anyway, It's solved now, but I cannot say why :/ El jueves, 21 de abril de 2016, 8:48:06 (UTC-3), Lisandro escribió: > > 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? > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.