Skip to content

Commit 030d8b6

Browse files
author
priyanshu.solanki
committed
fix: handle non-text columns in getTagUsage query
- Only apply empty string check for text columns (tag1-tag7) - Numeric/date/boolean columns only check IS NOT NULL - Cast values to text for consistent output
1 parent 511d891 commit 030d8b6

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

apps/sim/lib/knowledge/tags/service.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -589,21 +589,31 @@ export async function getTagUsage(
589589
const tagSlot = def.tagSlot
590590
validateTagSlot(tagSlot)
591591

592+
// Build WHERE conditions based on field type
593+
// Text columns need both IS NOT NULL and != '' checks
594+
// Numeric/date/boolean columns only need IS NOT NULL
595+
const fieldType = getFieldTypeForSlot(tagSlot)
596+
const isTextColumn = fieldType === 'text'
597+
598+
const whereConditions = [
599+
eq(document.knowledgeBaseId, knowledgeBaseId),
600+
isNull(document.deletedAt),
601+
isNotNull(sql`${sql.raw(tagSlot)}`),
602+
]
603+
604+
// Only add empty string check for text columns
605+
if (isTextColumn) {
606+
whereConditions.push(sql`${sql.raw(tagSlot)} != ''`)
607+
}
608+
592609
const documentsWithTag = await db
593610
.select({
594611
id: document.id,
595612
filename: document.filename,
596-
tagValue: sql<string>`${sql.raw(tagSlot)}`,
613+
tagValue: sql<string>`${sql.raw(tagSlot)}::text`,
597614
})
598615
.from(document)
599-
.where(
600-
and(
601-
eq(document.knowledgeBaseId, knowledgeBaseId),
602-
isNull(document.deletedAt),
603-
isNotNull(sql`${sql.raw(tagSlot)}`),
604-
sql`${sql.raw(tagSlot)} != ''`
605-
)
606-
)
616+
.where(and(...whereConditions))
607617

608618
usage.push({
609619
tagName: def.displayName,

0 commit comments

Comments
 (0)