Skip to content

[BUG] SQL import fails with NOT NULL constraint error on asn_int column #65

@monozoide

Description

@monozoide

📝 Bug Summary

The SQL import process fails when attempting to import maillogsentinel events into the SQLite database. The error indicates that the asn_int column in the maillogsentinel_events table is receiving NULL values but has a NOT NULL constraint defined. This prevents the entire SQL import transaction from completing and leaves the database in an inconsistent state.

🔍 Steps to Reproduce

  1. Launch the database import mode by running: python3 /usr/local/bin/maillogsentinel.py --sql-import
  2. Wait for the extraction and offset saving to complete successfully
  3. Observe the SQL import process starting
  4. The SQL import process fails during transaction execution

❌ Actual Result

The SQL import process crashes with the following error:

sqlite3.IntegrityError: NOT NULL constraint failed: maillogsentinel_events.asn_int

The transaction rolls back (as intended) but the process exits with failure status without successfully importing the events. No data is written to the database.

✅ Expected Result

The SQL import process should complete successfully and import all event records from the exported SQL file into the maillogsentinel_events table without constraint violations.

🌍 Runtime Context

  • Affected version(s): 5.15.x
  • Environment(s): Production
  • OS: Debian 13.1 - Trixie
  • Python version: 3.13.x
  • Relevant file: /usr/local/bin/lib/maillogsentinel/sql_importer.py (line 467)

📋 Logs / Error Messages

▲ Starting SQL import process...
sql_db: SQLite error processing file 20251016_2052_maillogsentinel_export.sql: NOT NULL constraint failed: maillogsentinel_events.asn_int. The transaction in the file should have rolled back.
Traceback (most recent call last):
  File "/usr/local/bin/lib/maillogsentinel/sql_importer.py", line 467, in run_sql_import
    conn.executescript(
    ~~~~~~~~~~~~~~~~~~^
        sql_script
        ^^^^^^^^^^
    )  # This will commit if successful, or rollback if error within script
    ^
sqlite3.IntegrityError: NOT NULL constraint failed: maillogsentinel_events.asn_int

✗ Some steps failed. SQL import failed.

🔧 Workaround (if any)

Temporarily modify the maillogsentinel_events table schema to allow NULL values in the asn_int column, though this is not a proper fix and may cause data integrity issues downstream.

📊 Impact Assessment

  • Users affected: All users wishing to import the extracted data into the database
  • Systems affected: Production SQL import workflow
  • Business impact: SQL import feature is completely non-functional; events cannot be imported into the database for reporting/analysis

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions