-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Begin warning people about spaces in model names #9886
Merged
QMalcolm
merged 20 commits into
main
from
qmalcolm--9397-deprecate-spaces-in-model-names
Apr 12, 2024
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0ac4b3f
Add event type for deprecation of spaces in model names
QMalcolm a20ef5a
Begin emitting deprecation warning for spaces in model names
QMalcolm 1804c72
Only warn on first model name with spaces unless `--debug` is specified
QMalcolm b1c584f
Refactor `EventCatcher` so that the event to catch is setable
QMalcolm fb2547a
Update `tests_debug_when_spaces_in_name` to check for relevant `Note`…
QMalcolm 3665fcc
Add project flag to control whether spaces are allowed in model names
QMalcolm 41ef3f7
Log errors and raise exception when `allow_spaces_in_model_names` is …
QMalcolm cd62234
Add changie log for new manifest validation of spaces in model names
QMalcolm 117b6d4
Fix capitalization in `Note` event message about improper model names
QMalcolm 0352bf5
Update test to check `Note` event contents for total bad model names
QMalcolm f51d65a
Alter `SpacesInModelNameDeprecation` to inherit from `DynamicLevel`
QMalcolm 92fc679
Fixup changelog to be a fix not a feature
QMalcolm f7b6f2d
Fix `test_graph.py` config creation process to ensure flags exist on …
QMalcolm f1278a3
Use custom even for output invalid name counts instead of `Note` events
QMalcolm b7e5c60
Always log total invalid model names if atleast one
QMalcolm c509d75
Reduce duplicate `if` logic in `check_for_spaces_in_model_names`
QMalcolm c678cbc
Improve readability of logs related to problematic model names
QMalcolm a2d609f
Alter `TotalModelNamesWithSpacesDeprecation` message to handle singul…
QMalcolm 515b61b
Merge branch 'main' into qmalcolm--9397-deprecate-spaces-in-model-names
QMalcolm 9cdecaa
Remove duplicate import in `test_graph.py` introduced from merging in…
QMalcolm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Fixes | ||
body: Begin warning people about spaces in model names | ||
time: 2024-04-09T23:33:47.850166-07:00 | ||
custom: | ||
Author: QMalcolm | ||
Issue: "9397" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
tests/functional/manifest_validations/test_check_for_spaces_in_model_names.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import pytest | ||
|
||
from dataclasses import dataclass, field | ||
from dbt.cli.main import dbtRunner | ||
from dbt_common.events.base_types import BaseEvent, EventLevel, EventMsg | ||
from dbt.events.types import SpacesInModelNameDeprecation, TotalModelNamesWithSpacesDeprecation | ||
from dbt.tests.util import update_config_file | ||
from typing import Dict, List | ||
|
||
|
||
@dataclass | ||
class EventCatcher: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
event_to_catch: BaseEvent | ||
caught_events: List[EventMsg] = field(default_factory=list) | ||
|
||
def catch(self, event: EventMsg): | ||
if event.info.name == self.event_to_catch.__name__: | ||
self.caught_events.append(event) | ||
|
||
|
||
class TestSpacesInModelNamesHappyPath: | ||
def test_no_warnings_when_no_spaces_in_name(self, project) -> None: | ||
event_catcher = EventCatcher(SpacesInModelNameDeprecation) | ||
runner = dbtRunner(callbacks=[event_catcher.catch]) | ||
runner.invoke(["parse"]) | ||
assert len(event_catcher.caught_events) == 0 | ||
|
||
|
||
class TestSpacesInModelNamesSadPath: | ||
@pytest.fixture(scope="class") | ||
def models(self) -> Dict[str, str]: | ||
return { | ||
"my model.sql": "select 1 as id", | ||
} | ||
|
||
def tests_warning_when_spaces_in_name(self, project) -> None: | ||
QMalcolm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
event_catcher = EventCatcher(SpacesInModelNameDeprecation) | ||
total_catcher = EventCatcher(TotalModelNamesWithSpacesDeprecation) | ||
runner = dbtRunner(callbacks=[event_catcher.catch, total_catcher.catch]) | ||
runner.invoke(["parse"]) | ||
|
||
assert len(total_catcher.caught_events) == 1 | ||
assert len(event_catcher.caught_events) == 1 | ||
event = event_catcher.caught_events[0] | ||
assert "Model `my model` has spaces in its name. This is deprecated" in event.info.msg | ||
assert event.info.level == EventLevel.WARN | ||
|
||
|
||
class TestSpaceInModelNamesWithDebug: | ||
@pytest.fixture(scope="class") | ||
def models(self) -> Dict[str, str]: | ||
return { | ||
"my model.sql": "select 1 as id", | ||
"my model2.sql": "select 1 as id", | ||
} | ||
|
||
def tests_debug_when_spaces_in_name(self, project) -> None: | ||
spaces_check_catcher = EventCatcher(SpacesInModelNameDeprecation) | ||
total_catcher = EventCatcher(TotalModelNamesWithSpacesDeprecation) | ||
runner = dbtRunner(callbacks=[spaces_check_catcher.catch, total_catcher.catch]) | ||
runner.invoke(["parse"]) | ||
assert len(spaces_check_catcher.caught_events) == 1 | ||
assert len(total_catcher.caught_events) == 1 | ||
assert ( | ||
"Found 2 models with spaces in their names" in total_catcher.caught_events[0].info.msg | ||
) | ||
assert ( | ||
"Run again with `--debug` to see them all." in total_catcher.caught_events[0].info.msg | ||
) | ||
|
||
spaces_check_catcher = EventCatcher(SpacesInModelNameDeprecation) | ||
total_catcher = EventCatcher(TotalModelNamesWithSpacesDeprecation) | ||
runner = dbtRunner(callbacks=[spaces_check_catcher.catch, total_catcher.catch]) | ||
runner.invoke(["parse", "--debug"]) | ||
assert len(spaces_check_catcher.caught_events) == 2 | ||
assert len(total_catcher.caught_events) == 1 | ||
assert ( | ||
"Run again with `--debug` to see them all." | ||
not in total_catcher.caught_events[0].info.msg | ||
) | ||
|
||
|
||
class TestAllowSpacesInModelNamesFalse: | ||
@pytest.fixture(scope="class") | ||
def models(self) -> Dict[str, str]: | ||
return { | ||
"my model.sql": "select 1 as id", | ||
} | ||
|
||
def test_dont_allow_spaces_in_model_names(self, project): | ||
spaces_check_catcher = EventCatcher(SpacesInModelNameDeprecation) | ||
runner = dbtRunner(callbacks=[spaces_check_catcher.catch]) | ||
runner.invoke(["parse"]) | ||
assert len(spaces_check_catcher.caught_events) == 1 | ||
assert spaces_check_catcher.caught_events[0].info.level == EventLevel.WARN | ||
|
||
config_patch = {"flags": {"allow_spaces_in_model_names": False}} | ||
update_config_file(config_patch, project.project_root, "dbt_project.yml") | ||
|
||
spaces_check_catcher = EventCatcher(SpacesInModelNameDeprecation) | ||
runner = dbtRunner(callbacks=[spaces_check_catcher.catch]) | ||
result = runner.invoke(["parse"]) | ||
assert not result.success | ||
assert "Model names cannot contain spaces" in result.exception.__str__() | ||
assert len(spaces_check_catcher.caught_events) == 1 | ||
assert spaces_check_catcher.caught_events[0].info.level == EventLevel.ERROR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you going to do this TODO before merging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not. That would entail opening a a PR in dbt-common and also getting it released, and I didn't want that to block this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up tasks assigned to me:
_error_tag
and useerror_tag
provided by dbt-common #9914error_tag
helper toui.py
dbt-common#107