Skip to content

fix(database): suggest closest supported type on schema typos#264

Merged
divyasinghds merged 1 commit into
developfrom
fix/sqlalchemy-type-did-you-mean
Jun 15, 2026
Merged

fix(database): suggest closest supported type on schema typos#264
divyasinghds merged 1 commit into
developfrom
fix/sqlalchemy-type-did-you-mean

Conversation

@divyasinghds

@divyasinghds divyasinghds commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

A new user typing BIGINTEGER (mixing BIGINT with Python's int), BOLEAN (missing O), NUMRIC (missing E), etc. used to get a bare Unsupported MySQL type: <typo> error with no hint. They had to spelunk the schema docs or guess.

Fix

Levenshtein-based "Did you mean X?" hint in _get_sqlalchemy_type's ValueError. Threshold d ≤ 3 — close enough to catch realistic typos (BIGINTEGER, INTGER, NUMRIC, BOLEAN, VARCAHR), narrow enough that GEOMETRY (d=6 to nearest) gets no misleading hint.

The error also prints the full supported-type list, so cases where edit-distance-nearest ≠ intent-nearest (e.g. BIGINTEGER's nearest by edits is INTEGER, even though the user clearly wanted BIGINT) still get help — BIGINT is right there in the list.

Test plan

  • BIGINTEGER → "Did you mean 'INTEGER'" + BIGINT in the supported list
  • GEOMETRY → no "Did you mean" (stays Unsupported only)
  • Parametrised: INTGER→INTEGER, NUMRIC→NUMERIC, BOLEAN→BOOLEAN, VARCAHR→VARCHAR

Surfaced by adversarial new-user testing N3 (parent #261).

🤖 Generated with Claude Code


Note

Low Risk
Only changes error text for invalid schema types; valid type mapping and DDL behavior are unchanged.

Overview
Unsupported MySQL type strings in user schemas now get actionable ValueError messages instead of a bare "Unsupported" line.

_get_sqlalchemy_type calls a new _suggest_type helper (Levenshtein distance ≤ 3 against type_mapping keys). Close typos like BIGINTEGER, INTGER, or NUMRIC raise Did you mean '…'? plus a Supported types: list sorted from the mapping. Distant names such as GEOMETRY still fail without a misleading suggestion.

Tests cover the suggestion path, the no-suggestion path, and a parametrized set of common misspellings.

Reviewed by Cursor Bugbot for commit 6088793. Bugbot is set up for automated code reviews on this repo. Configure here.

A new user typing ``BIGINTEGER`` (mixing MySQL's BIGINT with Python's
``int``), ``BOLEAN`` (missing an O), ``NUMRIC`` (missing an E), etc.
used to get a bare ``Unsupported MySQL type: <typo>`` error with no
hint about what's actually supported. They'd have to spelunk the
schema docs or guess.

## Fix

Add a Levenshtein-based "Did you mean X?" hint to ``_get_sqlalchemy_type``'s
ValueError. The threshold (d ≤ 3) is the empirical sweet spot:
  - close enough to catch every realistic typo we've seen in adversarial
    testing (single-letter swap, missing letter, repeated letter,
    common prefix/suffix confusion)
  - wide enough to fail-silently on genuine unrelated types (a real
    ``GEOMETRY`` request stays "Unsupported" with no misleading hint)

The error ALSO prints the full supported-type list so:
  - the suggestion gets the user 80% of the way there
  - the list catches the cases where the closest-by-distance suggestion
    isn't the closest-by-intent (e.g. BIGINTEGER's nearest by edits is
    INTEGER (d=3), even though the user clearly wanted BIGINT (d=4) —
    the printed list has BIGINT right next to INTEGER)

## Tests

- ``test_get_sqlalchemy_type_typo_suggests_correction``: BIGINTEGER
  surfaces the INTEGER suggestion + the BIGINT alternative is in the
  supported list
- ``test_get_sqlalchemy_type_typo_no_suggestion_for_distant_input``:
  GEOMETRY (d=6 to nearest) gets no hint, only the supported list
- Parametrised cases over realistic typos: INTGER→INTEGER, NUMRIC→NUMERIC,
  BOLEAN→BOOLEAN, VARCAHR→VARCHAR

## Surfaced by

Adversarial new-user test pass against v0.3.10-rc2, scenario N3:
``BIGINTEGER`` got a bare unhelpful error.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@divyasinghds divyasinghds self-assigned this Jun 15, 2026
@LukasWodka

Copy link
Copy Markdown
Collaborator

👋 Heads-up — Code review queue is at 15 / 8

Above the WIP limit. The team convention is to review existing PRs before opening new work.

Open PRs currently in Code review (oldest first):

Pull from review before opening new work. (This is a nudge from the kanban WIP check, not a block.)

@divyasinghds divyasinghds merged commit 3b6bf34 into develop Jun 15, 2026
7 checks passed
@divyasinghds divyasinghds deleted the fix/sqlalchemy-type-did-you-mean branch June 15, 2026 11:11
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.

3 participants