Problem with Model Class

I took the example code from Anvil Docs | Checks and Validation and stripped it down to the bare essentials:

from anvil.tables import app_tables


class TodoItem(app_tables.todos.Row, buffered=True, attrs=True, client_writeable=True):
    def _do_delete(self, from_client):
        super()._do_delete()

    def _do_update(self, updates, from_client):
        super()._do_update(updates)

    @classmethod
    def _do_create(cls, values, from_client):
        return super()._do_create(values)


test = TodoItem(task="test")
test.save()

This gives me an error when I run it:

ErrorLoadingUserCode: Error loading user code: get_base_model_cls.<locals>.Row._do_create() missing 1 required positional argument: 'from_client'

If I pass from_client to the super’s method, I get a permission error:

anvil.server.PermissionDenied: Cannot write to table 'todos' from client code.

What am I missing here?

Clone link:

EDIT
using super()._do_create(values, False) works but that feels wrong.

just pass on the from_client value


class TodoItem(app_tables.todos.Row, buffered=True, attrs=True, client_writeable=True):
    def _do_delete(self, from_client):
        super()._do_delete(from_client)

    def _do_update(self, updates, from_client):
        super()._do_update(updates, from_client)

    @classmethod
    def _do_create(cls, values, from_client):
        return super()._do_create(values, from_client)

We’ll fix those docs :grimacing:

As I said, that just gives me a permissions error.

I think you’ve misspelt client_writable in the inheritance definition (you’ve got an extra e).

(That…should probably produce a louder error!)

Oh good grief. and other slightly more vulgar words…

1 Like

We’ll make sure we raise an error there in future, so that others don’t suffer the same fate

4 Likes