Skip to content

fix(contract): refuse floating-point columns as upsert primary keys - #82

Merged
carolsimone merged 1 commit into
mainfrom
fix/float-pk-primary-key
Oct 11, 2026
Merged

carolsimone merged 1 commit into
mainfrom
fix/float-pk-primary-key

Conversation

@carolsimone

Copy link
Copy Markdown
Owner

What

Refuse a DOUBLE PRECISION column as an upsert primary_key, at contract
validation time.

Why

IEEE-754 treats 0.0 and -0.0 as equal and the warehouse collapses them to
a single key, so a float key makes ensure_unique_key reject rows mid-run.
DOUBLE_PRECISION is the only approximate type in the contract grammar
(NUMERIC is exact decimal128 and remains a valid key), so this guard is
type-precise: it moves an unwritable upsert's failure out of the write path
and keeps it out of the contract entirely.

Changes

  • continuo_python_runtime/contract/loader.py: _validate_primary_key rejects
    a key column whose parsed base is DOUBLE_PRECISION, with a clear
    ContractError.
  • tests/contract/test_loader.py: test_primary_key_column_cannot_be_floating_point.
  • CHANGELOG.md: extend the primary_key bullet.

Ships in 0.9.0 alongside the upsert write modes it protects.

🤖 Generated with Claude Code

https://claude.ai/code/session_0137E9XmyUXhwPTRrtNfivDw

A `DOUBLE PRECISION` primary-key column is unsafe: IEEE-754 treats `0.0`
and `-0.0` as equal, and the warehouse collapses them to one key, so
`ensure_unique_key` would reject such rows mid-run. `DOUBLE_PRECISION` is the
only approximate type in the contract grammar (NUMERIC is exact decimal128),
so refusing it at validation moves that failure out of the write path and
keeps an unwritable upsert out of the contract.

Signed-off-by: Simone Carolini <simonecarolini.sc@gmail.com>

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137E9XmyUXhwPTRrtNfivDw
@carolsimone
carolsimone merged commit a93eb69 into main Oct 11, 2026
28 checks passed
@carolsimone
carolsimone deleted the fix/float-pk-primary-key branch October 11, 2026 13:44
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