Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 06-27-2026, 09:24 AM   #1
Wiggo
Leftutti
Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.
 
Wiggo's Avatar
 
Posts: 633
Karma: 3671119
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
Custom Column: Template Error Python

With Calibre 9.10.0 I get this error in book details for two of my custom columns.

#Realname
Spoiler:
Code:
python:
def evaluate(book, context):
	from collections import defaultdict
	from calibre.utils.icu import sort_key

	alias_category = 'Pseudo.'
	alias_len = len(alias_category)
	fake_comma = '⸴'

	db = context.db.new_api
	aliases = defaultdict(list)
	# Parse the user categories, getting the real names. Build an inverted dict
	# pen_name: list(real_names). Why a list? Because a pen name can be used by
	# more than one real author.
	for real_name,pen_names in {cat[alias_len:]:vals
			for cat,vals in db.pref('user_categories').items()
				if cat.startswith(alias_category)}.items():
		for pn in pen_names:
			aliases[pn[0]].append(real_name)

	# For each author (pen name) for this book, get the real author(s)
	ans = set()
	for aut in book.authors:
		if aut in aliases:
			for real_name in aliases[aut]:
				# Replace commas with a fake comma because commas are used 
				# by calibre to separate values
				ans.add(real_name.replace(',', fake_comma) )
	return ', '.join(sorted(ans, key=sort_key))


#Alias
Spoiler:
Code:
python:
def evaluate(book, context):
	from collections import defaultdict
	from calibre.utils.icu import sort_key

	alias_category = 'Pseudo.'
	link_break = '<br/>'

	db = context.db.new_api

	# Build a set of other pen names for each author that is a pen name.
	# This loop only processes categories prefixed with alias_category
	all_pen_names = defaultdict(set)
	for pen_names in [[v[0] for v in vals]
			for cat,vals in db.pref('user_categories').items()
				if cat.startswith(alias_category)]:
		for pn in pen_names:
			all_pen_names[pn].update(pen_names)

	# Build the set of all pen names for all the authors of this book. Use a set
	# to remove duplicates.
	auts = set()
	for p in book.authors:
		if p in all_pen_names:
			auts.update(all_pen_names[p])

	# Now build the list of calibre search link URLs , one for each pen name.
	ans = list()
	for p in sorted(auts, key=sort_key): 
		# Replace any spaces with non-breaking spaces to prevent a name from
		# wrapping over two lines.
		ans.append(f'''<a href="calibre://search/_?eq='''
			f'''{('authors:"='+p + '"').encode().hex()}">'''
			f'''{p.replace(' ', '&nbsp;')}</a>''')

	# Combine all the URLS into a single string with the URLS separated by link_break.
	return link_break.join(ans)


After restart the error is only shown for #Alias

Click image for larger version

Name:	Screenshot 2026-06-27 150531.jpg
Views:	31
Size:	19.7 KB
ID:	224068

Edit: Calibre 9.9
Click image for larger version

Name:	Screenshot 2026-06-27 152858.jpg
Views:	22
Size:	8.3 KB
ID:	224069

Last edited by Wiggo; 06-27-2026 at 09:30 AM.
Wiggo is offline   Reply With Quote
Old 06-27-2026, 09:44 AM   #2
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,356
Karma: 1436993
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
I'm also getting this error for my 'Genre' column (built from others), which uses a Python template. It fixes itself if I folow this steps: open the Metadata Editor > click 'Next' record > close the Metadata Editor.

The error only happens in the Details panel. The book list always shows the calculated value.

This started a couple of versions ago, but I forgot to metion. I'm not sure if it was a beta version or 9.9.
thiago.eec is offline   Reply With Quote
Advert
Old 06-27-2026, 09:47 AM   #3
Wiggo
Leftutti
Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.
 
Wiggo's Avatar
 
Posts: 633
Karma: 3671119
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
For my #Alias column it didn't fix itself. I downgraded to Calibre 9.9. now.
Wiggo is offline   Reply With Quote
Old Yesterday, 12:11 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 46,347
Karma: 29630884
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
https://github.com/kovidgoyal/calibr...3715db75b5d53b
kovidgoyal is offline   Reply With Quote
Old Yesterday, 02:47 AM   #5
Wiggo
Leftutti
Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.
 
Wiggo's Avatar
 
Posts: 633
Karma: 3671119
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
Thank you
Wiggo is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom column template help wildfire070 Library Management 4 03-22-2024 11:28 AM
Help me with Custom Column template nqk Library Management 3 09-23-2016 10:22 PM
Bogus error in save template from custom column rbroberts Library Management 4 04-18-2014 04:54 AM
Template for custom column BeeTee-Ess Library Management 5 10-04-2013 08:55 PM
Write custom column from Python nsomlai Calibre 7 11-02-2010 11:12 AM


All times are GMT -4. The time now is 04:34 AM.


MobileRead.com is a privately owned, operated and funded community.