fix: product_category tree root node query + parent_id normalization - get_product_category: accept NULL/empty/'0' as root (parent_id IS NULL OR '' OR '0') - new_product_category: normalize empty/0 parent_id to NULL

This commit is contained in:
Hermes Agent 2026-06-22 13:59:18 +08:00
parent 24605f88e8
commit f13651e830
2 changed files with 14 additions and 10 deletions

View File

@ -2,12 +2,12 @@
ns = params_kw.copy() ns = params_kw.copy()
sql = '''select * from product_category where 1 = 1''' sql = '''select * from product_category where 1 = 1'''
id = ns.get('id') id = ns.get('id')
if id: if id and id != '0' and id != 'null' and id != 'undefined':
sql += " and parent_id = ${id}$" sql += " and parent_id = ${id}$"
else: else:
sql += " and parent_id is null" sql += " and (parent_id is null or parent_id = '' or parent_id = '0')"
sql += " order by name " sql += " order by sort_order, name "
db = DBPools() db = DBPools()
dbname = get_module_dbname('product_management') dbname = get_module_dbname('product_management')
async with db.sqlorContext(dbname) as sor: async with db.sqlorContext(dbname) as sor:

View File

@ -1,15 +1,19 @@
ns = params_kw.copy() ns = params_kw.copy()
for k,v in ns.items(): for k,v in ns.items():
if v == 'NaN' or v == 'null': if v == 'NaN' or v == 'null' or v == 'undefined' or v == '':
ns[k] = None ns[k] = None
id = params_kw.id
if not id or len(id) > 32: # Normalize parent_id: empty/0/None all mean root node (NULL)
pid = ns.get('parent_id')
if not pid or pid == '0':
ns['parent_id'] = None
id = params_kw.get('id')
if not id or len(str(id)) > 32:
id = uuid() id = uuid()
ns['id'] = id ns['id'] = id
userorgid = await get_userorgid() userorgid = await get_userorgid()
if not userorgid: if not userorgid:
return { return {