fix: "fetch from" was broken on SQLite (#35774)

SQLite (like PostgreSQL) doesn't support `INNER JOIN` within `UPDATE`
We can use the psql fallback we anyway had.

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang 2026-01-08 18:30:14 +05:30 committed by GitHub
parent 6ef39f3253
commit 4c58eba58b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -362,19 +362,7 @@ class DocType(Document):
continue # Invalid expression
link_df = new_meta.get_field(link_fieldname)
if frappe.db.db_type == "postgres":
update_query = """
UPDATE `tab{doctype}`
SET `{fieldname}` = source.`{source_fieldname}`
FROM `tab{link_doctype}` as source
WHERE `{link_fieldname}` = source.name
"""
if df.not_nullable:
update_query += "AND `{fieldname}`=''"
else:
update_query += "AND ifnull(`{fieldname}`, '')=''"
else:
if frappe.db.db_type == "mariadb":
update_query = """
UPDATE `tab{doctype}` as target
INNER JOIN `tab{link_doctype}` as source
@ -386,6 +374,18 @@ class DocType(Document):
else:
update_query += "WHERE ifnull(`target`.`{fieldname}`, '')=''"
else:
update_query = """
UPDATE `tab{doctype}`
SET `{fieldname}` = source.`{source_fieldname}`
FROM `tab{link_doctype}` as source
WHERE `{link_fieldname}` = source.name
"""
if df.not_nullable:
update_query += "AND `{fieldname}`=''"
else:
update_query += "AND ifnull(`{fieldname}`, '')=''"
self.flags.update_fields_to_fetch_queries.append(
update_query.format(
link_doctype=link_df.options,