<commit_before>import frappe

def execute():
	frappe.reload_doc('desk', 'doctype', 'todo')

	query = '''
		SELECT
			name, reference_type, reference_name, {} as assignees
		FROM
			`tabTodo`
		WHERE
			not reference_type IS NULL and not reference_name IS NULL
		GROUP BY
			reference_type, reference_name
	'''

	assignments = frappe.db.multisql({
		'mariadb': query.format('GROUP_CONCAT(DISTINCT `owner`)'),
		'postgres': query.format('STRING_AGG(DISTINCT "owner", ",")')
	}, as_dict=True)

	for doc in assignments:
		assignments = doc.assignees.split(',')
		print('assignments', assignments)
		frappe.db.set_value(
			doc.reference_type,
			doc.reference_name,
			'_assign',
			frappe.as_json(assignments),
			update_modified=False
		)<commit_msg>fix: use coalesce<commit_after>import frappe

def execute():
	frappe.reload_doc('desk', 'doctype', 'todo')

	query = '''
		SELECT
			name, reference_type, reference_name, {} as assignees
		FROM
			`tabTodo`
		WHERE
			COALESCE(reference_type, '') != '' and
			COALESCE(reference_name, '') != ''
		GROUP BY
			reference_type, reference_name
	'''

	assignments = frappe.db.multisql({
		'mariadb': query.format('GROUP_CONCAT(DISTINCT `owner`)'),
		'postgres': query.format('STRING_AGG(DISTINCT "owner", ",")')
	}, as_dict=True)

	for doc in assignments:
		assignments = doc.assignees.split(',')
		frappe.db.set_value(
			doc.reference_type,
			doc.reference_name,
			'_assign',
			frappe.as_json(assignments),
			update_modified=False
		)
{'fraction_non_alphanumeric': 0.14430209035738367, 'fraction_numerical': 0.0, 'mean_word_length': 4.66412213740458, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2888344', 'n_tokens_mistral': 606, 'n_tokens_neox': 534, 'n_words': 100}