Skip to content

Conversation

alanmcruickshank
Copy link
Member

@alanmcruickshank alanmcruickshank commented Sep 25, 2024

This is a test to see whether this approach passes other tests for resolving the conversation on slack with warnings about fixes being attempted in an unparsable file. The original poster was seeing lots of the error message Fixes for ... not applied, it would re-cause the same error and Fixes for ... not applies, as it would result in an unparsable file. Please report this as a bug with a minimal query which demonstrates this warning.

The issue was that an unparsable file we being passed to fix. Because it was already unparsable, the validation was always failing - and hence the error messages. However this isn't a bug with sqlfluff per-se, it's a bug with the sql file being passed in. The warning messages are still unhelpful however.

We don't have many test cases around fixing unparsable files either, so this revises the warning logic a little, and also puts a test case around that functionality. I also managed to cover some code which was previous uncovered (whoop)!

The test case isn't ideal because I couldn't show different behaviour for using fix_even_unparsable, but it's better that in was before, and hopefully we'll find a better test case in future.

Copy link
Contributor

github-actions bot commented Sep 25, 2024

Coverage Results ✅

Name    Stmts   Miss  Cover   Missing
-------------------------------------
TOTAL   18371      0   100%

237 files skipped due to complete coverage.

@coveralls
Copy link

coveralls commented Sep 25, 2024

Coverage Status

coverage: 99.985%. remained the same
when pulling 0c67b82 on ac/unparsable
into d69a511 on main.

@alanmcruickshank alanmcruickshank changed the title [DRAFT] Try and resolve the unfixable files issues Revise warnings with fixing unfixable files. Sep 26, 2024
@alanmcruickshank alanmcruickshank marked this pull request as ready for review September 26, 2024 18:38
@@ -118,16 +118,39 @@ def apply_fixes(
dialect: "Dialect",
rule_code: str,
fixes: Dict[int, AnchorEditInfo],
fix_even_unparsable: bool = False,
Copy link
Member

Choose a reason for hiding this comment

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

One thing that confuses me -- if a file has parsing errors and fix_even_unparsable is false, should this function even be called? There may be some nuance here I don't understand or have forgotten, but my initial instinct suggests there may be a more sweeping upstream fix possible. (By "sweeping", I mean at the file level rather than the parse subtree level.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point 🤔 .

When I check now, what you're suggesting does actually already exist, but further up in the linting process. In lint_paths() we only persist the file if it's free of templating errors, which means you're kind of right.

Is that what you mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

@barrywhart - I think you're right that we need to rationalise how fix_even_unparsable is used across the codebase. On inspection it's pretty inconsistent, including how it interacts with fix and when it's read from config and when it's read from a keyword argument.

I think it's a bigger issue to fix, and I'm going to suggest doing that as a separate piece of work. I've make an issue to track it: #6264

@alanmcruickshank alanmcruickshank merged commit dbbf765 into main Sep 28, 2024
29 checks passed
@alanmcruickshank alanmcruickshank deleted the ac/unparsable branch September 28, 2024 17:54
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