Skip to content

Bug: Category edit always fails — boolean is_active not coerced to integer for SQLite #63

Description

@khaira777

Problem

Editing any category field (name, description, color, active toggle) on the Products page fails with "Failed to save category".

Root Cause

In main/routes/categories.ts:98, the PUT route passes is_active directly from req.body to better-sqlite3:

.run(name, slug, description, parent_id, sort_order, is_active, color, icon, now(), req.params.id);

The frontend sends is_active as a JavaScript boolean (true/false). SQLite has no native boolean type — it uses 0/1. When better-sqlite3 binds a JS boolean, it may not coerce it to integer properly, causing the COALESCE(?, is_active) in the UPDATE to fail.

This affects ALL category updates, not just the active toggle, because the same .run() call includes all parameters — if any parameter binding fails, the entire statement fails.

Additionally, the frontend error handler (products/page.tsx:252) swallows the error with no logging:

catch { toast.error('Failed to save category'); }

The actual error message from the server is never shown or logged.

Fix

1. Backend: Convert boolean to integer (categories.ts)

const activeInt = is_active !== undefined ? (is_active ? 1 : 0) : undefined;

db.prepare(`...`).run(name, slug, description, parent_id, sort_order, activeInt, color, icon, now(), req.params.id);

2. Frontend: Log the actual error (products/page.tsx)

catch (err) {
  console.error('[Category] Save error:', err);
  toast.error('Failed to save category');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions