windmill
windmill copied to clipboard
[Aider PR] Fix: data studio, set to null rather than
This PR was created automatically by Aider to fix an external issue: data studio, set to null rather than
Aider Output
────────────────────────────────────────────────────────────────────────────────
Warning: it's best to only add files that need changes to the chat.
https://aider.chat/docs/troubleshooting/edit-errors.html
Aider v0.83.1
Main model: gemini/gemini-2.5-pro-preview-05-06 with diff-fenced edit format
Weak model: gemini/gemini-2.5-flash-preview-04-17
Git repo: .git with 3,557 files
Warning: For large repos, consider using --subtree-only and .aiderignore
See: https://aider.chat/docs/faq.html#can-i-use-aider-in-a-large-mono-repo
Repo-map: using 4096 tokens, auto refresh
Added
frontend/src/lib/components/apps/components/display/dbtable/queries/insert.ts to
the chat.
Added frontend/src/lib/components/apps/components/display/dbtable/utils.ts to
the chat.
Added frontend/src/lib/components/apps/editor/component/components.ts to the
chat.
Added frontend/src/lib/components/flows/flowInfers.ts to the chat.
Added .cursor/rules/svelte5-best-practices.mdc to the chat (read-only).
Added .cursor/rules/windmill-overview.mdc to the chat (read-only).
Added .cursor/rules/rust-best-practices.mdc to the chat (read-only).
https://aider.chat/HISTORY.html#release-notes
Initial repo scan can be slow in larger repos, but only happens once.
The issue suggests that when a user intends to override a database column's
default value but doesn't specify a new value or explicitly set it to NULL, it's
incorrectly becoming NULL. Instead, an alternative like an empty string (for
string types) or the database's original default might be expected.
To address this, I'll make the following changes in
frontend/src/lib/components/apps/components/display/dbtable/insert.ts:
1 Modify getUserDefaultValue to correctly process defaultUserValue when it's a
falsy but defined value (e.g., empty string '', 0, false). Currently, if
(column.defaultUserValue) would incorrectly treat these as if no user default
was provided. I'll change this to if (column.defaultUserValue !== undefined).
2 Introduce a helper function isStringType to check if a given database
datatype is a string type. This will be used to apply specific logic for
string columns.
3 Update formatDefaultValues:
• If overrideDefaultValue is true:
• If userDefaultValue is explicitly provided (i.e., not undefined after
calling getUserDefaultValue), use it.
• If userDefaultValue is undefined (meaning the user checked "override"
but didn't specify a value or explicit NULL):
• If the column is a string type (using isStringType), set its value
to "''" (an SQL empty string literal).
• Otherwise (for non-string types), let the value be undefined, which
will typically result in NULL in the SQL query. This is a sensible
default for non-string types when an override is requested without a
specific value.
• If overrideDefaultValue is false, the existing logic of using
userDefaultValue ?? c.defaultvalue remains appropriate.
These changes aim to ensure that overriding a default without specifying a value
results in an empty string for text-based columns, rather than an unintended
NULL, while preserving NULL for non-text columns or when explicitly requested.
frontend/src/lib/components/apps/components/display/dbtable/insert.ts
<<<<<<< SEARCH
function getUserDefaultValue(column: ColumnDef) {
if (column.defaultValueNull) {
return 'NULL'
} else if (column.defaultUserValue) {
return typeof column.defaultUserValue === 'string'
? `'${column.defaultUserValue}'`
: column.defaultUserValue
}
}
function formatDefaultValues(columns: ColumnDef[]): string {
const defaultValues = columns
.map((c) => {
const userDefaultValue = getUserDefaultValue(c)
if (c.overrideDefaultValue === true) {
return userDefaultValue
}
return userDefaultValue ?? c.defaultvalue
})
.join(', ')
=======
function getUserDefaultValue(column: ColumnDef) {
if (column.defaultValueNull) {
return 'NULL'
} else if (column.defaultUserValue !== undefined) {
return typeof column.defaultUserValue === 'string'
? `'${column.defaultUserValue}'`
: column.defaultUserValue
}
}
function isStringType(datatype: string): boolean {
if (!datatype) return false
const lowerType = datatype.toLowerCase()
// Covers common SQL string types like VARCHAR, CHAR, TEXT, NVARCHAR, NCHAR
// and also types like 'string' from BigQuery.
return lowerType.includes('char') || lowerType.includes('text') ||
lowerType.includes('string')
}
function formatDefaultValues(columns: ColumnDef[]): string {
const defaultValues = columns
.map((c) => {
const userDefaultValue = getUserDefaultValue(c)
if (c.overrideDefaultValue === true) {
// User wants to override the database default.
if (userDefaultValue !== undefined) {
// User specified an explicit override (e.g., a value, or
NULL via defaultValueNull)
return userDefaultValue
} else {
// User specified "override" but didn't provide a value or
check "set to NULL".
// For string types, interpret this as "override with empty
string".
// For non-string types, interpret as "override with NULL"
(by returning undefined).
if (isStringType(c.datatype)) {
return "''" // SQL empty string literal
}
return undefined // Will result in NULL for this column in
the INSERT statement
}
} else {
// User does not want to override the database default.
// Use user-specified default if available, otherwise use
database default.
return userDefaultValue ?? c.defaultvalue
}
})
.join(', ')
>>>>>>> REPLACE
Tokens: 48k sent, 995 received. Cost: $0.07 message, $0.07 session.
Applied edit to
frontend/src/lib/components/apps/components/display/dbtable/queries/insert.ts
Commit f08286d fix: Set empty string for overridden string defaults
Deploying windmill with
Cloudflare Pages
| Latest commit: |
f08286d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ca36d45f.windmill.pages.dev |
| Branch Preview URL: | https://aider-fix-linear-issue-win-9.windmill.pages.dev |
Aider fixed the insert but it seems that it had no issue on main, only on updates