Skip to content
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

Fix CI issue with tox #6137

Merged
merged 10 commits into from
Oct 25, 2022
8 changes: 8 additions & 0 deletions .changes/unreleased/Fixes-20221016-173742.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: Fixes
body: Add functors to ensure event types with str-type attributes are initialized
to spec, even when provided non-str type params.
time: 2022-10-16T17:37:42.846683-07:00
custom:
Author: versusfacit
Issue: "5436"
PR: "5874"
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20221017-151511.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: Fixed extra whitespace in strings introduced by black.
time: 2022-10-17T15:15:11.499246-05:00
custom:
Author: luke-bassett
Issue: "1350"
PR: "6086"
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20221017-155844.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: Clean up string formatting
time: 2022-10-17T15:58:44.676549-04:00
custom:
Author: eve-johns
Issue: "6068"
PR: "6082"
2 changes: 1 addition & 1 deletion .changie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ custom:
footerFormat: |
{{- $contributorDict := dict }}
{{- /* any names added to this list should be all lowercase for later matching purposes */}}
{{- $core_team := list "peterallenwebb" "emmyoop" "nathaniel-may" "gshank" "leahwicz" "chenyulinx" "stu-k" "iknox-fa" "versusfacit" "mcknight-42" "jtcohen6" "dependabot[bot]" "snyk-bot" "colin-rogers-dbt" }}
{{- $core_team := list "michelleark" "peterallenwebb" "emmyoop" "nathaniel-may" "gshank" "leahwicz" "chenyulinx" "stu-k" "iknox-fa" "versusfacit" "mcknight-42" "jtcohen6" "dependabot[bot]" "snyk-bot" "colin-rogers-dbt" }}
{{- range $change := .Changes }}
{{- $authorList := splitList " " $change.Custom.Author }}
{{- /* loop through all authors for a PR */}}
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def list_relations_without_caching(self, schema_relation: BaseRelation) -> List[
:rtype: List[self.Relation]
"""
raise NotImplementedException(
"`list_relations_without_caching` is not implemented for this " "adapter!"
"`list_relations_without_caching` is not implemented for this adapter!"
)

###
Expand Down
6 changes: 3 additions & 3 deletions core/dbt/clients/_jinja_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ def find_blocks(self, allowed_blocks=None, collect_raw_data=True):
if self.current:
linecount = self.data[: self.current.end].count("\n") + 1
dbt.exceptions.raise_compiler_error(
(
"Reached EOF without finding a close tag for " "{} (searched from line {})"
).format(self.current.block_type_name, linecount)
("Reached EOF without finding a close tag for {} (searched from line {})").format(
self.current.block_type_name, linecount
)
)

if collect_raw_data:
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/config/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class PartialProject(RenderComponents):
project_name: Optional[str] = field(
metadata=dict(
description=(
"The name of the project. This should always be set and will not " "be rendered"
"The name of the project. This should always be set and will not be rendered"
)
)
)
Expand Down Expand Up @@ -668,7 +668,7 @@ def hashed_name(self):
def get_selector(self, name: str) -> Union[SelectionSpec, bool]:
if name not in self.selectors:
raise RuntimeException(
f"Could not find selector named {name}, expected one of " f"{list(self.selectors)}"
f"Could not find selector named {name}, expected one of {list(self.selectors)}"
)
return self.selectors[name]["definition"]

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/context/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __new__(mcls, name, bases, dct):


class Var:
UndefinedVarError = "Required var '{}' not found in config:\nVars " "supplied to {} = {}"
UndefinedVarError = "Required var '{}' not found in config:\nVars supplied to {} = {}"
_VAR_NOTSET = object()

def __init__(
Expand Down
6 changes: 3 additions & 3 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def dispatch(
return macro

searched = ", ".join(repr(a) for a in attempts)
msg = f"In dispatch: No macro named '{macro_name}' found\n" f" Searched for: {searched}"
msg = f"In dispatch: No macro named '{macro_name}' found\n Searched for: {searched}"
raise CompilationException(msg)


Expand Down Expand Up @@ -220,12 +220,12 @@ def _repack_args(self, name: str, package: Optional[str]) -> List[str]:
def validate_args(self, name: str, package: Optional[str]):
if not isinstance(name, str):
raise CompilationException(
f"The name argument to ref() must be a string, got " f"{type(name)}"
f"The name argument to ref() must be a string, got {type(name)}"
)

if package is not None and not isinstance(package, str):
raise CompilationException(
f"The package argument to ref() must be a string or None, got " f"{type(package)}"
f"The package argument to ref() must be a string or None, got {type(package)}"
)

def __call__(self, *args: str) -> RelationProxy:
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def handle(self):
self._handle.resolve(self)
except RecursionError as exc:
raise InternalException(
"A connection's open() method attempted to read the " "handle value"
"A connection's open() method attempted to read the handle value"
) from exc
return self._handle

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def _update_into(dest: MutableMapping[str, T], new_item: T):
existing = dest[unique_id]
if new_item.original_file_path != existing.original_file_path:
raise dbt.exceptions.RuntimeException(
f"cannot update a {new_item.resource_type} to have a new file " f"path!"
f"cannot update a {new_item.resource_type} to have a new file path!"
)
dest[unique_id] = new_item

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def process_freshness_result(result: FreshnessNodeResult) -> FreshnessNodeOutput
criteria = result.node.freshness
if criteria is None:
raise InternalException(
"Somehow evaluated a freshness result for a source " "that has no freshness criteria!"
"Somehow evaluated a freshness result for a source that has no freshness criteria!"
)
return SourceFreshnessOutput(
unique_id=unique_id,
Expand Down
1 change: 1 addition & 0 deletions core/dbt/events/adapter_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)


# N.B. No guarantees for what type param msg is.
@dataclass
class AdapterLogger:
name: str
Expand Down
17 changes: 17 additions & 0 deletions core/dbt/events/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ def level_tag(self) -> str:
return "error"


# Included to ensure classes with str-type message members are initialized correctly.
@dataclass # type: ignore[misc]
class AdapterEventStringFunctor:
def __post_init__(self):
super().__post_init__()
if not isinstance(self.base_msg, str):
self.base_msg = str(self.base_msg)


@dataclass # type: ignore[misc]
class EventStringFunctor:
def __post_init__(self):
super().__post_init__()
if not isinstance(self.msg, str):
self.msg = str(self.msg)


# prevents an event from going to the file
# This should rarely be used in core code. It is currently
# only used in integration tests and for the 'clean' command.
Expand Down
30 changes: 17 additions & 13 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
WarnLevel,
ErrorLevel,
Cache,
AdapterEventStringFunctor,
EventStringFunctor,
)
from dbt.events.format import format_fancy_output_line, pluralize

Expand Down Expand Up @@ -309,7 +311,7 @@ def message(self) -> str:


@dataclass
class AdapterEventDebug(DebugLevel, pt.AdapterEventDebug): # noqa
class AdapterEventDebug(DebugLevel, AdapterEventStringFunctor, pt.AdapterEventDebug): # noqa
def code(self):
return "E001"

Expand All @@ -318,7 +320,7 @@ def message(self):


@dataclass
class AdapterEventInfo(InfoLevel, pt.AdapterEventInfo): # noqa
class AdapterEventInfo(InfoLevel, AdapterEventStringFunctor, pt.AdapterEventInfo): # noqa
def code(self):
return "E002"

Expand All @@ -327,7 +329,7 @@ def message(self):


@dataclass
class AdapterEventWarning(WarnLevel, pt.AdapterEventWarning): # noqa
class AdapterEventWarning(WarnLevel, AdapterEventStringFunctor, pt.AdapterEventWarning): # noqa
def code(self):
return "E003"

Expand All @@ -336,7 +338,7 @@ def message(self):


@dataclass
class AdapterEventError(ErrorLevel, pt.AdapterEventError): # noqa
class AdapterEventError(ErrorLevel, AdapterEventStringFunctor, pt.AdapterEventError): # noqa
def code(self):
return "E004"

Expand Down Expand Up @@ -1218,7 +1220,9 @@ def message(self) -> str:

# TODO: switch to storing structured info and calling get_target_failure_msg
@dataclass
class InvalidDisabledSourceInTestNode(WarnLevel, pt.InvalidDisabledSourceInTestNode):
class InvalidDisabledSourceInTestNode(
WarnLevel, EventStringFunctor, pt.InvalidDisabledSourceInTestNode
):
def code(self):
return "I050"

Expand All @@ -1227,7 +1231,7 @@ def message(self) -> str:


@dataclass
class InvalidRefInTestNode(DebugLevel, pt.InvalidRefInTestNode):
class InvalidRefInTestNode(DebugLevel, EventStringFunctor, pt.InvalidRefInTestNode):
def code(self):
return "I051"

Expand Down Expand Up @@ -1334,7 +1338,7 @@ def message(self) -> str:


@dataclass
class MacroEventInfo(InfoLevel, pt.MacroEventInfo):
class MacroEventInfo(InfoLevel, EventStringFunctor, pt.MacroEventInfo):
def code(self):
return "M011"

Expand All @@ -1343,7 +1347,7 @@ def message(self) -> str:


@dataclass
class MacroEventDebug(DebugLevel, pt.MacroEventDebug):
class MacroEventDebug(DebugLevel, EventStringFunctor, pt.MacroEventDebug):
def code(self):
return "M012"

Expand Down Expand Up @@ -2261,7 +2265,7 @@ def message(self) -> str:


@dataclass
class RunResultError(ErrorLevel, pt.RunResultError):
class RunResultError(ErrorLevel, EventStringFunctor, pt.RunResultError):
def code(self):
return "Z024"

Expand Down Expand Up @@ -2299,7 +2303,7 @@ def message(self) -> str:


@dataclass
class FirstRunResultError(ErrorLevel, pt.FirstRunResultError):
class FirstRunResultError(ErrorLevel, EventStringFunctor, pt.FirstRunResultError):
def code(self):
return "Z028"

Expand All @@ -2308,7 +2312,7 @@ def message(self) -> str:


@dataclass
class AfterFirstRunResultError(ErrorLevel, pt.AfterFirstRunResultError):
class AfterFirstRunResultError(ErrorLevel, EventStringFunctor, pt.AfterFirstRunResultError):
def code(self):
return "Z029"

Expand Down Expand Up @@ -2446,7 +2450,7 @@ def message(self) -> str:


@dataclass
class GeneralWarningMsg(WarnLevel, pt.GeneralWarningMsg):
class GeneralWarningMsg(WarnLevel, EventStringFunctor, pt.GeneralWarningMsg):
def code(self):
return "Z046"

Expand Down Expand Up @@ -2476,7 +2480,7 @@ def message(self) -> str:


@dataclass
class RunResultWarningMessage(WarnLevel, pt.RunResultWarningMessage):
class RunResultWarningMessage(WarnLevel, EventStringFunctor, pt.RunResultWarningMessage):
def code(self):
return "Z049"

Expand Down
4 changes: 1 addition & 3 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,7 @@ def raise_patch_targets_not_found(patches):

def _fix_dupe_msg(path_1: str, path_2: str, name: str, type_name: str) -> str:
if path_1 == path_2:
return (
f"remove one of the {type_name} entries for {name} in this file:\n" f" - {path_1!s}\n"
)
return f"remove one of the {type_name} entries for {name} in this file:\n - {path_1!s}\n"
else:
return (
f"remove the {type_name} entry for {name} in one of these files:\n"
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_subset_graph(self, selected: Iterable[UniqueId]) -> "Graph":
for node in include_nodes:
if node not in new_graph:
raise ValueError(
"Couldn't find model '{}' -- does it exist or is " "it disabled?".format(node)
"Couldn't find model '{}' -- does it exist or is it disabled?".format(node)
)

return Graph(new_graph)
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/graph/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_package_names(nodes):

def alert_non_existence(raw_spec, nodes):
if len(nodes) == 0:
warn_or_error(f"The selection criterion '{str(raw_spec)}' does not match" f" any nodes")
warn_or_error(f"The selection criterion '{str(raw_spec)}' does not match any nodes")


def can_select_indirectly(node):
Expand Down
4 changes: 1 addition & 3 deletions core/dbt/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
colorama.init(wrap=True)

STDOUT_LOG_FORMAT = "{record.message}"
DEBUG_LOG_FORMAT = (
"{record.time:%Y-%m-%d %H:%M:%S.%f%z} " "({record.thread_name}): " "{record.message}"
)
DEBUG_LOG_FORMAT = "{record.time:%Y-%m-%d %H:%M:%S.%f%z} ({record.thread_name}): {record.message}"


def get_secret_env() -> List[str]:
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def initial_config(self, fqn: List[str]) -> ContextConfig:
)
else:
raise InternalException(
f"Got an unexpected project version={config_version}, " f"expected 2"
f"Got an unexpected project version={config_version}, expected 2"
)

def config_dict(
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/generic_test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def tags(self) -> List[str]:
tags = [tags]
if not isinstance(tags, list):
raise_compiler_error(
f"got {tags} ({type(tags)}) for tags, expected a list of " f"strings"
f"got {tags} ({type(tags)}) for tags, expected a list of strings"
)
for tag in tags:
if not isinstance(tag, str):
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _parse_generic_test(

except ParsingException as exc:
context = _trimmed(str(target))
msg = "Invalid test config given in {}:" "\n\t{}\n\t@: {}".format(
msg = "Invalid test config given in {}:\n\t{}\n\t@: {}".format(
target.original_file_path, exc.msg, context
)
raise ParsingException(msg) from exc
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/parser/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def parse_source(self, target: UnpatchedSourceDefinition) -> ParsedSourceDefinit

if not isinstance(config, SourceConfig):
raise InternalException(
f"Calculated a {type(config)} for a source, but expected " f"a SourceConfig"
f"Calculated a {type(config)} for a source, but expected a SourceConfig"
)

default_database = self.root_project.credentials.database
Expand Down Expand Up @@ -317,7 +317,7 @@ def get_unused_msg(
unused_tables: Dict[SourceKey, Optional[Set[str]]],
) -> str:
msg = [
"During parsing, dbt encountered source overrides that had no " "target:",
"During parsing, dbt encountered source overrides that had no target:",
]
for key, table_names in unused_tables.items():
patch = self.manifest.source_patches[key]
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def on_skip(self):
print_run_result_error(result=self.skip_cause, newline=False)
if self.skip_cause is None: # mypy appeasement
raise InternalException(
"Skip cause not set but skip was somehow caused by " "an ephemeral failure"
"Skip cause not set but skip was somehow caused by an ephemeral failure"
)
# set an error so dbt will exit with an error code
error_message = (
Expand Down
Loading