Use `if 'webapi' in self.context:` instead. `hasattr` is too old-school.