Skip to content

Feat: add typo suggestions to MODEL block field errors#4661

Merged
treysp merged 3 commits intomainfrom
trey/model-block-errors
Jun 10, 2025
Merged

Feat: add typo suggestions to MODEL block field errors#4661
treysp merged 3 commits intomainfrom
trey/model-block-errors

Conversation

@treysp
Copy link
Copy Markdown
Contributor

@treysp treysp commented Jun 4, 2025

Before

  Invalid extra fields {'descriptions', 'dialects'} in the model definition
  Invalid extra fields {'batch_sizes'} in the model kind 'INCREMENTAL_BY_TIME_RANGE'

After

  Invalid field names present in the MODEL block: 'dialects', 'descriptions'
  
    - dialects: Did you mean 'dialect'?
    - descriptions: Did you mean 'description'?
  Invalid field name present in the MODEL block 'kind INCREMENTAL_BY_TIME_RANGE' field: 'batch_sizes'. Did you mean 'batch_size'?

@treysp treysp force-pushed the trey/model-block-errors branch from c4b032e to ba370d9 Compare June 4, 2025 22:54
@treysp treysp requested a review from a team June 4, 2025 23:09
Comment thread sqlmesh/core/model/kind.py Outdated
Comment on lines +278 to +285
extra_field_names = "'" + "', '".join(extra_fields) + "'"

all_fields = klass.all_fields()
close_matches = {}
for field in extra_fields:
matches = get_close_matches(field, all_fields, n=1)
if matches:
close_matches[field] = matches[0]
Copy link
Copy Markdown
Contributor

@benfdking benfdking Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not important: This looks great to me and is a lovely bit of kit!

@izeigerman this is an example of the thing I talked about on Tuesday when I was saying building with sympathy for the "LSP"

To me, this is a perfect example of something that could be a diagnostic, e.g., if this were a structured error, we could

  1. Highlight it in line, e.g., under the misspelled word
  2. Suggest a code action that could correct the mistyped word to the 'close_match'

Actually even more than just for the LSP if you printed it correctly, you could print a link to the file with the right code line that IDE's would pick up as a link to the right file and place.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hear you. Though, I don't believe all the relevant information is available here—for example, the position of the field in the code. So Trey wouldn't be able to express this sympathy in the PR even if he wanted to, since he doesn't have access to the original source, only the Pydantic model object.

@treysp treysp force-pushed the trey/model-block-errors branch from a304be2 to 51dc7df Compare June 10, 2025 14:30
@treysp treysp merged commit c9a26ec into main Jun 10, 2025
26 checks passed
@treysp treysp deleted the trey/model-block-errors branch June 10, 2025 15:25
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.

4 participants