User templates are lost after "Save Composite Columns" plugin is executed and Action Chains/Editor Chains are initialized.
After putting the print.tracestack at other place, I've found this:
Spoiler:
File "C:\git\calibre\src\calibre\debug.py", line 231, in main
File "C:\git\calibre\src\calibre\gui_launch.py", line 73, in calibre
File "C:\git\calibre\src\calibre\gui2\main.py", line 552, in main
File "C:\git\calibre\src\calibre\gui2\main.py", line 564, in run_main
File "C:\git\calibre\src\calibre\gui2\main.py", line 402, in run_gui
File "C:\git\calibre\src\calibre\gui2\main.py", line 418, in run_gui_
File "C:\git\calibre\src\calibre\gui2\main.py", line 376, in initialize
File "C:\git\calibre\src\calibre\gui2\main.py", line 355, in initialize_db
File "C:\git\calibre\src\calibre\gui2\main.py", line 312, in initialize_db_stage2
File "C:\git\calibre\src\calibre\gui2\main.py", line 260, in start_gui
File "C:\git\calibre\src\calibre\gui2\ui.py", line 446, in post_initialize_actions
File "C:\git\calibre\src\calibre\db\cache.py", line 2798, in __del__
File "C:\git\calibre\src\calibre\db\cache.py", line 2836, in close
File "C:\git\calibre\src\calibre\db\backend.py", line 1363, in close
File "C:\git\calibre\src\calibre\utils\formatter_functi ons.py", line 2764, in unload_user_template_functions
File "C:\git\calibre\src\calibre\utils\formatter_functi ons.py", line 109, in unregister_functions
File "C:\git\calibre\src\calibre\utils\formatter_functi ons.py", line 102, in _register_functions
At this point, library functions disappear. Checking backend.py, I can see this:
So, no plugin is responsible. I'm thinking this code is not called if there is no plugin, and that's the reason that it works in that case.
Well, knowing this, at least I know where to look for the functions.