Skip to content

Commit

Permalink
Added root object
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jsikorski committed Jan 21, 2025
1 parent cd0ff29 commit f99a296
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/snowflake/cli/_plugins/cortex/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def search(

if not columns:
columns = []

conn = get_cli_context().connection
root = get_cli_context().root_object

search_service = (
Root(conn)
root
.databases[conn.database]
.schemas[conn.schema]
.cortex_search_services[service]
Expand Down
7 changes: 7 additions & 0 deletions src/snowflake/cli/api/cli_global_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
from pathlib import Path
from typing import TYPE_CHECKING, Iterator

from cryptography.utils import cached_property

from snowflake.cli.api.connections import ConnectionContext, OpenConnectionCache
from snowflake.cli.api.exceptions import MissingConfiguration
from snowflake.cli.api.metrics import CLIMetrics
from snowflake.cli.api.output.formats import OutputFormat
from snowflake.cli.api.rendering.jinja import CONTEXT_KEY
from snowflake.connector import SnowflakeConnection
from snowflake.core import Root

if TYPE_CHECKING:
from snowflake.cli.api.project.definition_manager import DefinitionManager
Expand Down Expand Up @@ -196,6 +199,10 @@ def _should_force_mute_intermediate_output(self) -> bool:
"""Computes whether cli_console output should be muted."""
return self._manager.output_format == OutputFormat.JSON

@cached_property
def root_object(self) -> Root:
return Root(self.connection)


_CLI_CONTEXT_MANAGER: ContextVar[_CliGlobalContextManager | None] = ContextVar(
"cli_context", default=None
Expand Down
3 changes: 3 additions & 0 deletions tests_integration/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ def test_connection_not_existing_schema(
f'Could not use schema "{schema.upper()}". Object does not exist'
in result.output
)

def test_root_object(snowflake_session):
root = snowflake_session.root_object
1 change: 0 additions & 1 deletion tests_integration/test_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


@pytest.mark.integration
@pytest.mark.skip # TODO: when we have Cortex activated on test account, unskip this and setup part in sql script
@pytest.mark.skipif(
sys.version_info >= (3, 12),
reason="Snowflake Python API currently does not support Python 3.12 and greater",
Expand Down

0 comments on commit f99a296

Please sign in to comment.