fix: handle missing columns in older OmniFocus database schemas - #4
Open
brettporter wants to merge 1 commit into
Open
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 keycrash on every query, making the operator completely unusable.Affected columns absent in older schemas:
Task:datePlanned,effectiveDatePlanned,repetitionScheduleTypeString,catchUpAutomatically,repetitionAnchorDateKeyContext(tags):allowsNextAction,childrenAreMutuallyExclusive,parentFix
Introduces two small helpers in
hybrid.py:_get_table_columns(conn, table)— introspectsPRAGMA table_infoto detect available columns (available for future use)_row_get(row, key, default=None)— safesqlite3.Rowaccessor that returns a default instead of raisingIndexErrorwhen a column is absentAll direct
row[key]accesses for the affected columns are replaced with_row_get()calls with sensible defaults:datePlanned/effectiveDatePlanned→NonerepetitionScheduleTypeString→NonecatchUpAutomatically→FalserepetitionAnchorDateKey→None(falls back to"due_date"via_ANCHOR_DATE_MAP)allowsNextAction→True(permissive default)childrenAreMutuallyExclusive→FalseTests
Adds
TestOlderSchemaCompatibilitywith three tests that create an in-memory SQLite DB omitting the newer columns and assert thatlist_tasks,list_tags, andget_allall 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.