Skip to content

fix: handle missing columns in older OmniFocus database schemas - #4

Open
brettporter wants to merge 1 commit into
HelloThisIsFlo:mainfrom
brettporter:fix/older-omnifocus-schema-compatibility
Open

fix: handle missing columns in older OmniFocus database schemas#4
brettporter wants to merge 1 commit into
HelloThisIsFlo:mainfrom
brettporter:fix/older-omnifocus-schema-compatibility

Conversation

@brettporter

Copy link
Copy Markdown

Problem

Users running OmniFocus 4.3.3 on older macOS versions (that cannot upgrade
to the latest OmniFocus) have an older database schema that is missing
columns added in newer versions. This causes an IndexError: No item with that key crash on every query, making the operator completely unusable.

Affected columns absent in older schemas:

  • Task: datePlanned, effectiveDatePlanned, repetitionScheduleTypeString, catchUpAutomatically, repetitionAnchorDateKey
  • Context (tags): allowsNextAction, childrenAreMutuallyExclusive, parent

Fix

Introduces two small helpers in hybrid.py:

  • _get_table_columns(conn, table) — introspects PRAGMA table_info to detect available columns (available for future use)
  • _row_get(row, key, default=None) — safe sqlite3.Row accessor that returns a default instead of raising IndexError when a column is absent

All direct row[key] accesses for the affected columns are replaced with _row_get() calls with sensible defaults:

  • datePlanned / effectiveDatePlannedNone
  • repetitionScheduleTypeStringNone
  • catchUpAutomaticallyFalse
  • repetitionAnchorDateKeyNone (falls back to "due_date" via _ANCHOR_DATE_MAP)
  • allowsNextActionTrue (permissive default)
  • childrenAreMutuallyExclusiveFalse

Tests

Adds TestOlderSchemaCompatibility with three tests that create an in-memory SQLite DB omitting the newer columns and assert that list_tasks, list_tags, and get_all all succeed and return sensible values.

Full test suite: 2,564 passed, 97% coverage.

Verified

Tested locally against OmniFocus 4.3.3 on an older macOS schema — all queries now work correctly.

OmniFocus adds new columns in database schema upgrades. Users on older
macOS versions that cannot run the latest OmniFocus (e.g. OmniFocus 4.3.3
on an older OS) have a database schema that is missing columns introduced
in later versions, causing IndexError crashes in _map_task_row,
_map_project_row, _map_tag_row, and _build_repetition_rule.

Affected columns (absent in older schemas):
  Task:    datePlanned, effectiveDatePlanned,
           repetitionScheduleTypeString, catchUpAutomatically,
           repetitionAnchorDateKey
  Context: allowsNextAction, childrenAreMutuallyExclusive, parent

Fix: introduce two small helpers in hybrid.py:
  - _get_table_columns(conn, table): introspects PRAGMA table_info to
    detect which columns exist (available for future use)
  - _row_get(row, key, default=None): safe sqlite3.Row accessor that
    returns a default instead of raising IndexError when a column is
    absent

Replace all direct row[key] accesses for the affected columns with
_row_get() calls, with appropriate defaults:
  - datePlanned / effectiveDatePlanned         → None
  - repetitionScheduleTypeString               → None
  - catchUpAutomatically                       → False
  - repetitionAnchorDateKey                    → None (→ 'due_date' via _ANCHOR_DATE_MAP)
  - allowsNextAction                           → True (permissive default)
  - childrenAreMutuallyExclusive               → False

Add TestOlderSchemaCompatibility with three tests that create an
in-memory SQLite DB omitting the newer columns and assert that
list_tasks, list_tags, and get_all all succeed and return sensible
values (planned_date=None, children_are_mutually_exclusive=False).
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.

1 participant