Got the db, thanks.
Problem: it works for me on Windows 10 Pro, calibre 7.2 standard (not from source), minimal configuration (no plugins). It also works from source. It also works with my test library configuration that has a zillion plugins.
This screen capture shows what I see when I open the template tester on a book.
This capture shows the template tester calling one of your functions:
Are you seeing the problem when using the template tester? Or when you are defining a template for some other purpose such as a column rule or a composite column? When opening a library, or when switching to that library?