Repository navigation
fix: warn when multi-repo projects resolve to different state connections or gateways #6279
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,7 @@ | |
| from sqlmesh.core.config import ( | ||
| CategorizerConfig, | ||
| Config, | ||
| GatewayConfig, | ||
| load_configs, | ||
| ) | ||
| from sqlmesh.core.config.connection import ConnectionConfig | ||
|
|
@@ -421,6 +422,7 @@ def __init__( | |
| self._linters: t.Dict[str, Linter] = {} | ||
| self._loaded: bool = False | ||
| self._materializations_loaded: bool = False | ||
| self._multi_repo_connections_validated: bool = False | ||
| self._load_state: bool = load_state | ||
| self._uncached_model_names: t.Set[str] = set() | ||
| self._selector_cls = selector or NativeSelector | ||
|
|
@@ -3364,7 +3366,58 @@ def _print_state_versions( | |
| version = f"{getattr(previous_versions, attribute)} -> {version}" | ||
| self.console.log_status_update(f"{label}: {version}") | ||
|
|
||
| def _validate_multi_repo_connections(self) -> None: | ||
| """Validates that the projects of a multi-repo context can share this context's state. | ||
|
|
||
| Global concerns like the state connection and engine adapters are resolved once for | ||
| the entire context, so projects that disagree on them would be silently ignored. | ||
| """ | ||
| if self._multi_repo_connections_validated or len(self.configs) < 2: | ||
| return | ||
| self._multi_repo_connections_validated = True | ||
|
|
||
| state_connection_source: t.Optional[t.Tuple[Path, ConnectionConfig]] = None | ||
| gateway_sources: t.Dict[str, t.Tuple[Path, GatewayConfig]] = {} | ||
|
|
||
| for path, config in self.configs.items(): | ||
| gateway_name = self.gateway or config.default_gateway_name | ||
| try: | ||
| state_connection = config.get_state_connection( | ||
| gateway_name | ||
| ) or config.get_connection(gateway_name) | ||
| except ConfigError: | ||
| state_connection = None | ||
|
|
||
| if state_connection is not None: | ||
| if state_connection_source is None: | ||
| state_connection_source = (path, state_connection) | ||
| elif state_connection != state_connection_source[1]: | ||
| self.console.log_warning( | ||
| f"Project '{path}' resolves to a different state connection than project " | ||
| f"'{state_connection_source[0]}', whose state connection is used for all " | ||
| "projects. SQLMesh reads environment state from a single state connection, " | ||
| "so environments planned against the other projects' own state connections " | ||
| "are not visible here and their models may never be evaluated by `plan` " | ||
| "or `run`. Configure the same `state_connection` in every project." | ||
| ) | ||
|
|
||
| gateways = config.gateways | ||
| if not isinstance(gateways, dict): | ||
| continue | ||
| for name, gateway in gateways.items(): | ||
| gateway_source = gateway_sources.get(name) | ||
| if gateway_source is None: | ||
| gateway_sources[name] = (path, gateway) | ||
| elif gateway != gateway_source[1]: | ||
| self.console.log_warning( | ||
| f"Gateway '{name}' is defined differently in project '{path}' than in " | ||
| f"project '{gateway_source[0]}'; the definition from " | ||
| f"'{gateway_source[0]}' is used for all projects." | ||
|
Comment on lines
+3411
to
+3415
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. Do not warn that variable-only gateway differences are overridden. The gateway comparison in Change the gateway check so the warning describes only fields that the context shares across projects. Alternatively, keep the whole-object comparison and reword the message so it does not claim that a variables-only difference is overridden. Update the matching statement in the multi-repo guide to the same rule.
|
||
| ) | ||
|
|
||
| def _new_state_sync(self) -> StateSync: | ||
| if self._provided_state_sync is None: | ||
| self._validate_multi_repo_connections() | ||
| return self._provided_state_sync or self._scheduler.create_state_sync(self) | ||
|
|
||
| def _new_selector( | ||
|
|
||
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.
Compare the resolved gateway connection, not only the gateway definition.
A gateway without its own
connectioninherits the rootdefault_connection.Config.get_connectionapplies that fallback per project, and normalization does not copy it into the gateway. Two projects can therefore define identicallocalgateways with the samestate_connection, but different rootdefault_connectionvalues. Both checks treat these projects as consistent.engine_adapterskeeps only the first project's connection forlocal. Models from the other project that uselocalthen run against the first project's database, and no warning is emitted.Extend the gateway comparison to use the connection that each project resolves for that gateway name. Warn when the resolved connections differ, and name the project whose connection is used. Handle a project whose connection cannot be resolved the same way the state check handles
ConfigError.