![]() |
#1 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,628
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Problem with defined function in templates
Hello,
I think I've already had this problem but I don't remember where to look at for solving it. I've got some functions defined in bbdd to use in templates. However, they don't appear now when I query the defined functions, only the standard ones appear. The debug log shows the following information (obt_lei is one of my functions): Spoiler:
Where can I check to try to debug the error? Thanks in advance. |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
It seems that the user defined functions have disappeared. I don't know why. There haven't been any changes to stored templates and functions for a long time.
You can check if they are still in the DB by looking in metadata_db_prefs_backup.json for the key "user_template_functions", or directly in the database in the preferences table. If the functions are there then I will need the metadata.db to debug why they aren't being loaded. If they are not there then you must think about what might have happened. I can imagine a database restore losing the functions. You can probably put them back by editing the preferences table and adding that key from a backup. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,628
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Both entries (metadata_db_prefs_backup.json and metadata.db) are present. And it doesn't happen only at one library, it happens at least at two of them.
|
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
In which case I need a sample database where loading the functions fails. The database must include the functions and at least one book entry that uses the functions. You can send me the entire metadata.db (zipped) if you don't mind me seeing what is in it.
Send it to me at calibre_bugs at charleshaley dot org. I don't need any books. I wish MobileRead supported sending attachments via private message. |
![]() |
![]() |
![]() |
#5 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,628
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
I totally agree about private messages. File sent.
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
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? |
![]() |
![]() |
![]() |
#7 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,628
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
I'm attaching what I see in Spanish at the template tester. As you see, the functions are not present and, if I try to use it, it fails. I've tested only with template tester, and problem exists both when I open the library or change to a library.
When I create a composite column, as there is no help, no list, but I can use the function and, later, it works. |
![]() |
![]() |
![]() |
#8 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
As I said, I can't make it fail, either when using the template tester on a book or when defining a composite column. (Note: when defining a new column you can right-click on the template box to open a template editor.)
I wonder if it has something to do with a plugin. Could you zip your calibre config folder and send it to me so I can run a test with the same plugins and settings that you have? I know that Action Chains does things with template functions. Do you have any chains that run at startup? You could try running calibre with Code:
calibre --ignore-plugins Another test would be for you to open the library with a clean (empty) configuration folder. What I did was copy the config folder somewhere then emptied the original. When I started calibre I got the startup wizard, where I picked the library containing your metadata.db. This process removes all plugins and all settings. If you can run from source then we might learn something from adding a debugging print to the template tester. The two lines of code are: Code:
print(f'Using standard builtin and custom functions: {all_functions is None}') traceback.print_stack() |
![]() |
![]() |
![]() |
#9 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,628
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
The problem is a plugin, yes. Executing calibre --ignore-plugins means that the template tester finds the functions (BTW, the template editor from the column definition has the same behavior). I'm going to try to see if I remember how to run calibre from source (I did it long time ago and my memory is quite volatile if I do a thing only once).
|
![]() |
![]() |
![]() |
#10 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#11 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,628
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
I thinkI've done something wrong because this is the log:
Spoiler:
|
![]() |
![]() |
![]() |
#12 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
calibre-debug -g The goal is to see whether something is calling the template tester with its own functions. It may end up showing us nothing, in which case I will need to put the print statements elsewhere. |
|
![]() |
![]() |
![]() |
#13 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,628
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
This is the result with print:
Spoiler:
tracestack is failing. |
![]() |
![]() |
![]() |
#14 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,628
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
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:
At this point, library functions disappear. Checking backend.py, I can see this: Spoiler:
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. ![]() Last edited by Terisa de morgan; 01-01-2024 at 03:50 PM. |
![]() |
![]() |
![]() |
#15 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Thank you for taking the time to continue tracing this.
What those traces say is that python garbage collection is collecting (deleting) the current database, thus closing it or a copy of it. In other words, I think that something is opening the database of the current library or creating a copy (copy.deepcopy()) of an open instance variable, saving it as a local variable. When GC (garbage collection) is called that local copy is closed. There are timing problems here. The local variable might not be collected in some situations. The only way I can see to verify this is to remove the plugins one at a time to see if the problem goes away. I would start with Action Chains, as I checked SaveCompositeColumns and it doesn't reopen or make a copy of the DB. If the plugin is found then we can look for why the variable that GC collects is created. I hope Kovid notices this thread. He will probably have ideas on why it is happening and how to find it. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calibre 6 - problem loading user-defined template functions | davidfor | Library Management | 4 | 07-12-2022 04:37 AM |
Help Please - user defined USB problem | HeavyTZM | Library Management | 4 | 11-26-2011 09:06 PM |
Help Please - user defined USB problem | HeavyTZM | General Discussions | 4 | 11-26-2011 05:36 PM |
PRS-650 Search dictionary function problem | Salt | Sony Reader | 15 | 01-17-2011 06:36 PM |