Skip to content

Fix vehicle creation failing with null id#203

Merged
javedh-dev merged 2 commits intojavedh-dev:devfrom
rderewianko:fix/vehicle-null-id
Mar 30, 2026
Merged

Fix vehicle creation failing with null id#203
javedh-dev merged 2 commits intojavedh-dev:devfrom
rderewianko:fix/vehicle-null-id

Conversation

@rderewianko
Copy link
Copy Markdown
Contributor

Fixes #202

When creating a vehicle, the client sends id: null in the request body. Drizzle's $defaultFn only fires when a value is undefined, not when it's explicitly null, so the UUID was never generated and SQLite threw a NOT NULL constraint error.

Fix: explicitly generate the UUID in addVehicle instead of relying on the schema default.

Copy link
Copy Markdown
Owner

@javedh-dev javedh-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comment

@dufourux
Copy link
Copy Markdown

Hi, and thanks a lot for the work. You app looks very promising, I would love to use it for sure.
I'm afraid I'm encountering the same situation now :
2026-03-29 13:17:31 [info]: 90.76.254.33 - POST - /api/vehicles
Vehicles POST error: DrizzleQueryError: Failed query: insert into "vehicles" ("id", "make", "model", "year", "license_plate", "vin", "color", "odometer", "image", "fuel_type", "custom_fields", "created_at", "updated_at") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) returning "id", "make", "model", "year", "license_plate", "vin", "color", "odometer", "image", "fuel_type", "custom_fields", "created_at", "updated_at"
params: ,Renault,Megane 3 GT,2012,CH077GE,,#aaaaaa,158000,,diesel,
at LibSQLPreparedQuery.queryWithCache (file:///app/build/server/chunks/db-BMWV9NEL.js:4447:15)
at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
at async LibSQLPreparedQuery.values (file:///app/build/server/chunks/db-BMWV9NEL.js:4820:12)
at async LibSQLPreparedQuery.all (file:///app/build/server/chunks/db-BMWV9NEL.js:4763:18)
at async addVehicle (file:///app/build/server/chunks/vehicleService-pEm1JhPv.js:72:20)
at async file:///app/build/server/chunks/_server.ts-tcq22z-0.js:26:15
at async withRouteErrorHandling (file:///app/build/server/chunks/route-handler-DbcTSUqk.js:14:10)
at async render_endpoint (file:///app/build/server/chunks/index-BEe6PqRh.js:651:20)
at async resolve (file:///app/build/server/chunks/index-BEe6PqRh.js:4040:88)
at async paraglideMiddleware (file:///app/build/server/chunks/hooks.server-C8jCzkW1.js:368:9) {
query: 'insert into "vehicles" ("id", "make", "model", "year", "license_plate", "vin", "color", "odometer", "image", "fuel_type", "custom_fields", "created_at", "updated_at") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) returning "id", "make", "model", "year", "license_plate", "vin", "color", "odometer", "image", "fuel_type", "custom_fields", "created_at", "updated_at"',
params: [
null, 'Renault',
'Megane 3 GT', 2012,
'CH077GE', null,
'#aaaaaa', 158000,
null, 'diesel',
null
],
cause: LibsqlError: SQLITE_CONSTRAINT: NOT NULL constraint failed: vehicles.id
at mapSqliteError (file:///app/node_modules/.pnpm/@libsql+client@0.17.0/node_modules/@libsql/client/lib-esm/sqlite3.js:434:16)
at executeStmt (file:///app/node_modules/.pnpm/@libsql+client@0.17.0/node_modules/@libsql/client/lib-esm/sqlite3.js:337:15)
at Sqlite3Client.execute (file:///app/node_modules/.pnpm/@libsql+client@0.17.0/node_modules/@libsql/client/lib-esm/sqlite3.js:82:16)
... 4 lines matching cause stack trace ...
at QueryPromise.all (file:///app/build/server/chunks/db-BMWV9NEL.js:3700:28)
at QueryPromise.execute (file:///app/build/server/chunks/db-BMWV9NEL.js:3709:41)
at QueryPromise.then (file:///app/build/server/chunks/db-BMWV9NEL.js:1495:17) {
code: 'SQLITE_CONSTRAINT',
extendedCode: 'SQLITE_CONSTRAINT_NOTNULL',
rawCode: 1299,
[cause]: SqliteError: NOT NULL constraint failed: vehicles.id
at convertError (/app/node_modules/.pnpm/libsql@0.5.22/node_modules/libsql/index.js:59:12)
at Object.next (/app/node_modules/.pnpm/libsql@0.5.22/node_modules/libsql/index.js:385:17)
at Statement.all (/app/node_modules/.pnpm/libsql@0.5.22/node_modules/libsql/index.js:403:18)
at executeStmt (file:///app/node_modules/.pnpm/@libsql+client@0.17.0/node_modules/@libsql/client/lib-esm/sqlite3.js:321:34)
at Sqlite3Client.execute (file:///app/node_modules/.pnpm/@libsql+client@0.17.0/node_modules/@libsql/client/lib-esm/sqlite3.js:82:16)
at file:///app/build/server/chunks/db-BMWV9NEL.js:4822:61
at LibSQLPreparedQuery.queryWithCache (file:///app/build/server/chunks/db-BMWV9NEL.js:4445:22)
at LibSQLPreparedQuery.values (file:///app/build/server/chunks/db-BMWV9NEL.js:4820:23)
at LibSQLPreparedQuery.all (file:///app/build/server/chunks/db-BMWV9NEL.js:4763:29)
at QueryPromise.all (file:///app/build/server/chunks/db-BMWV9NEL.js:3700:28) {
code: 'SQLITE_CONSTRAINT_NOTNULL',
rawCode: 1299
}
}
}

Is there something I'm doing wrong ?

Strip id from payload in serializeVehiclePayload so the runtime null
from the UI request body never reaches Drizzle, allowing $defaultFn
to generate the UUID as intended.
@rderewianko rderewianko force-pushed the fix/vehicle-null-id branch from 3f0bf8d to 83d2304 Compare March 30, 2026 03:17
@javedh-dev javedh-dev merged commit 02b42d9 into javedh-dev:dev Mar 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cant ctreate Vehicle with latest Docker image

3 participants