Skip to content

Preserve composite foreign-key column correspondence in SQLite - #85

Merged
xrotwang merged 1 commit into
cldf:masterfrom
antonsoo:fix/composite-foreign-key-order
Oct 25, 2026
Merged

xrotwang merged 1 commit into
cldf:masterfrom
antonsoo:fix/composite-foreign-key-order

Conversation

@antonsoo

Copy link
Copy Markdown
Contributor

TableSpec.from_table_metadata sorts the referencing and referenced columns independently. This changes a composite foreign key's meaning when the two sets of names sort differently. A dataset can pass CSVW validation and then fail csvw2sqlite with FOREIGN KEY constraint failed.

For example, child(left, right) -> parent(zeta, alpha) becomes child(left, right) -> parent(alpha, zeta). Keep both column lists in their declared order.

The two regression cases insert valid rows, reject invalid pairs, and check cascading deletes with both declaration orders. Both fail before this change. The full suite passes on Python 3.12 (827 passed, 16 expected failures) and 3.9 (830 passed, 13 expected failures); Flake8 passes for the changed files.

CSVW validation, CLI SQLite export and SQL joins were also checked using recorded lexical data. Eight previously failing export configurations now work; eight working configurations retain identical rows and joins.

@xrotwang
xrotwang merged commit 82ee2f5 into cldf:master Oct 25, 2026
5 checks passed
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.

2 participants