Skip to content

Commit aa85711

Browse files
committed
Fix tests
1 parent 1667540 commit aa85711

3 files changed

Lines changed: 11 additions & 30 deletions

File tree

sqlmesh/core/renderer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ def _resolve_tables(
319319
expand = set(expand) | {
320320
name
321321
for name, snapshot in snapshots.items()
322-
if snapshot.is_embedded or not snapshot.categorized
322+
if snapshot.is_embedded
323+
or (snapshot.is_model and snapshot.model.is_sql and not snapshot.categorized)
323324
}
324325

325326
if expand:

tests/core/test_context.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,6 @@ def test_environment_statements(tmp_path: pathlib.Path):
14091409
],
14101410
after_all=[
14111411
"@grant_schema_usage()",
1412-
"@grant_select_privileges()",
14131412
"@grant_usage_role(@schemas, 'admin')",
14141413
],
14151414
)
@@ -1429,29 +1428,6 @@ def test_environment_statements(tmp_path: pathlib.Path):
14291428
expression,
14301429
)
14311430

1432-
create_temp_file(
1433-
tmp_path,
1434-
pathlib.Path(macros_dir, "grant_select_file.py"),
1435-
"""
1436-
from sqlmesh.core.macros import macro
1437-
from sqlmesh.core.snapshot.definition import to_view_mapping
1438-
1439-
@macro()
1440-
def grant_select_privileges(evaluator):
1441-
if evaluator._environment_naming_info and evaluator.runtime_stage == 'before_all':
1442-
mapping = to_view_mapping(
1443-
evaluator._snapshots.values(), evaluator._environment_naming_info
1444-
)
1445-
return [
1446-
stmt
1447-
for stmt in [
1448-
f"GRANT SELECT ON VIEW {view_name} TO ROLE admin_role;"
1449-
for view_name in mapping.values()
1450-
]
1451-
]
1452-
""",
1453-
)
1454-
14551431
create_temp_file(
14561432
tmp_path,
14571433
pathlib.Path(macros_dir, "grant_schema_file.py"),
@@ -1494,13 +1470,18 @@ def grant_usage_role(evaluator, schemas, role):
14941470
context = Context(paths=tmp_path, config=config)
14951471
snapshots = {s.name: s for s in context.snapshots.values()}
14961472

1473+
from sqlmesh.core.snapshot.definition import SnapshotChangeCategory
1474+
1475+
for s in snapshots.values():
1476+
s.categorize_as(SnapshotChangeCategory.BREAKING)
1477+
14971478
environment_statements = context._environment_statements[0]
14981479
before_all = environment_statements.before_all
14991480
after_all = environment_statements.after_all
15001481
python_env = environment_statements.python_env
15011482

1502-
assert isinstance(python_env["to_view_mapping"], Executable)
1503-
assert isinstance(python_env["grant_select_privileges"], Executable)
1483+
assert isinstance(python_env["grant_schema_usage"], Executable)
1484+
assert isinstance(python_env["grant_usage_role"], Executable)
15041485

15051486
before_all_rendered = render_statements(
15061487
statements=before_all,
@@ -1520,11 +1501,11 @@ def grant_usage_role(evaluator, schemas, role):
15201501
snapshots=snapshots,
15211502
environment_naming_info=EnvironmentNamingInfo(name="prod"),
15221503
runtime_stage=RuntimeStage.BEFORE_ALL,
1504+
engine_adapter=context.engine_adapter,
15231505
)
15241506

15251507
assert after_all_rendered == [
15261508
"GRANT USAGE ON SCHEMA db TO user_role",
1527-
"GRANT SELECT ON VIEW memory.db.test_after_model TO ROLE admin_role",
15281509
'GRANT USAGE ON SCHEMA "db" TO "admin"',
15291510
]
15301511

@@ -1539,7 +1520,6 @@ def grant_usage_role(evaluator, schemas, role):
15391520

15401521
assert after_all_rendered_dev == [
15411522
"GRANT USAGE ON SCHEMA db__dev TO user_role",
1542-
"GRANT SELECT ON VIEW memory.db__dev.test_after_model TO ROLE admin_role",
15431523
'GRANT USAGE ON SCHEMA "db__dev" TO "admin"',
15441524
]
15451525

tests/core/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4598,7 +4598,7 @@ def test_multi(mocker):
45984598
)
45994599
assert (
46004600
context.render("silver.d").sql()
4601-
== '''SELECT "c"."col_a" AS "col_a", 2 AS "two", 'repo_2' AS "dup" FROM "memory"."silver"."c" AS "c"'''
4601+
== '''SELECT "c"."col_a" AS "col_a", 2 AS "two", 'repo_2' AS "dup" FROM (SELECT DISTINCT "a"."col_a" AS "col_a" FROM (SELECT 1 AS "col_a", 'b' AS "col_b", 1 AS "one", 'repo_1' AS "dup") AS "a") AS "c"'''
46024602
)
46034603
context._new_state_sync().reset(default_catalog=context.default_catalog)
46044604
plan = context.plan_builder().build()

0 commit comments

Comments
 (0)