Skip to content

audit: every data write fails to persist sys_audit_log — "table sys_audit_log has no column named organization_id" (sql driver) #1532

@xuyushun441-sys

Description

@xuyushun441-sys

Summary

On the SQL (better-sqlite3) driver, every record insert/update triggers an audit write that fails, because the audit writer's INSERT INTO sys_audit_log includes an organization_id column the table doesn't have. The error is caught (Audit write failed) so the business mutation still succeeds — but no audit row is ever persisted.

Version

@objectstack/* 7.6.0, driver-sql (better-sqlite3), single-tenant.

Error (verbatim, on every write)

ERROR Insert operation failed {"object":"sys_audit_log","error":{"message":
  "insert into `sys_audit_log` (`action`, `created_at`, `created_by`, `id`, `new_value`,
   `object_name`, `old_value`, `organization_id`, `record_id`, `tenant_id`, `updated_at`,
   `updated_by`, `user_id`) values (...) returning *
   - table sys_audit_log has no column named organization_id"}}
   at SqlDriver.create (@objectstack/driver-sql/dist/index.mjs:322)
   at _ObjectQL.triggerHooks (@objectstack/objectql/dist/index.mjs:5935)
WARN  Audit write failed {"object":"crm_lead","action":"create", ...}

Note the INSERT column list emits both organization_id and tenant_id; the created sys_audit_log table is missing organization_id.

Repro

  1. Any stack on the sqlite driver with the audit service active (default slate).
  2. Create or update any record via REST / ObjectQL.
  3. Server log shows Insert operation failed {object: sys_audit_log …} followed by Audit write failed.

Impact

  • Audit logging is silently non-functional on this driver — compliance / audit-trail gap that looks fine from the app's perspective (writes succeed).
  • Every mutation pays a failed SQL round-trip + caught exception (noise + minor perf).

Likely cause

The sys_audit_log system-object definition / migration in the audit plugin is out of sync with the columns the audit writer INSERTs (organization_id, and possibly tenant_id). Either the table needs those columns added to its schema/migration, or the writer should stop emitting columns the object doesn't declare.


Found while upgrading objectstack-ai/hotcrm to 7.6 (objectstack-ai/hotcrm#365). The audit failure is non-fatal but reproduces on 100% of writes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions