Field_filter hook not running?

Hi all, I’ve been having an issue where, as far as I can tell, the field_filter hook is not running, even though the card_did_render and webview_will_set_content hooks at least are running. I feel like I’m missing something simple…

To reproduce:

OS: Ubuntu 20.04.5 LTS
python==3.9.10
Qt==6.3.1
PyQt==6.3.1
anki==2.1.54
aqt==2.1.54

This is the add-on I am using:

from anki import hooks
from aqt import gui_hooks


def f(*args):
    print("field_filter run")
    return ""


hooks.field_filter.append(f)
hooks.card_did_render.append(lambda *args: print("card_did_render run"))
gui_hooks.webview_will_set_content.append(
    lambda *args: print("webview_will_set_content run")
)

Here is the output on startup:

Anki starting...
Initial setup...
Running with temporary Qt5 compatibility shims.
Run with DISABLE_QT5_COMPAT=1 to confirm compatibility with Qt6.
Preparing to run...
Command 'dbus-send --session --print-reply=literal --reply-timeout=1000 --dest=org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read string:'org.freedesktop.appearance' string:'color-scheme'' returned non-zero exit status 1.
Qt info: 

GL Type: desktop
Surface Type: OpenGL
Surface Profile: CompatibilityProfile
Surface Version: 4.6
QSG RHI Backend: OpenGL
Using Supported QSG Backend: yes
Using Software Dynamic GL: no
Using Multithreaded OpenGL: yes

Init Parameters:
  *  application-name Anki 
  *  browser-subprocess-path /usr/local/share/anki/lib/PyQt6/Qt6/libexec/QtWebEngineProcess 
  *  create-default-gl-context  
  *  disable-features ConsolidatedMovementXY,InstalledApp,BackgroundFetch,WebOTP,WebPayments,WebUSB,PictureInPicture 
  *  disable-setuid-sandbox  
  *  disable-speech-api  
  *  enable-features NetworkServiceInProcess,TracingServiceInProcess 
  *  enable-threaded-compositing  
  *  in-process-gpu  
  *  use-gl desktop 
 
webview_will_set_content run
Starting main loop...
webview_will_set_content run
webview_will_set_content run
webview_will_set_content run
webview_will_set_content run
mpv not found, reverting to mplayer

And on reviewing a card:

webview_will_set_content run
webview_will_set_content run
webview_will_set_content run
webview_will_set_content run
card_did_render run

The field_filter hook doesn’t seem to run. Any help would be much appreciated. Thank you!

It only runs when there are custom filters in the template. If you put something like {{foo:Front}} in the front template for example, it will run.

2 Likes

Wow yup I knew I was missing something simple… thanks!