Silent Server calls with model classes

If I’m using model classes, is there some way to suppress the spinner when they make server calls?

Some equivalent of anvil.server.call_s ?

Have you tried with the context manager?

1 Like

Nope! I’d forgotten that exists!

Thank you

Well, I have no tried it and I get an error saying that no_loading_indicator doesn’t exist.

If I try:

from anvil.server import no_loading_indicator

I get an import error.

With:

import anvil.server


with anvil.server.no_loading_indicator:
   ...

I get an attribute error

presumably you get this on the server?

anvil.server doesn’t have no_loading_indicator on the server.
Maybe there should be one for convenience

But for now I guess you could do something like

try:
    from anvil.server import no_loading_indicator
except ImportError:
    import contextlib
    no_loading_indicator = contextlib.nullcontext

1 Like

Ah. Of course. I’m still not quite used to thinking about code that needs to run both sides of the fence!

However, that nullcontext doesn’t seem to work either. I get:

AttributeError: __enter__

1 Like

ah - we probably want it to be an instance rather than the callable

try:
    from anvil.server import no_loading_indicator
except ImportError:
    import contextlib
    no_loading_indicator = contextlib.nullcontext()

yeah, I was just reading the docs and came to the same conclusion.

That now works, in that it imports just fine, but I still can’t suppress the spinner.

If I’ve used the @server_method to decorate a model class method, how do I use the no_loading_indicator?

It might be worth making this to a feature request


class MyModel(app_tables.foo.Row):
    @anvil.server.server_method
    def do_something_on_the_server(cls):
        ...


If you do something like the above, then any place you call row.do_something_on_the_server() will need the context manager


with anvil.server.no_loading_indicator:
    row.do_something_on_the_server()

I suspect you’re putting the no loading indicator on the inside of the server method and hoping it’ll work?

3 Likes

Yeah, I was. It’s bloody obvious it needs to go on the call, isn’t it?!!

All I can say in defence is that I got up early this morning and haven’t had coffee yet.

Thanks all. Not sure who gets the solution kudos here.

3 Likes