Skip to content

Commit

Permalink
Fix modifying global that is used in a policy on a type it refers to (#…
Browse files Browse the repository at this point in the history
…7310)

Fix is simple: we need to call _propagate_if_expr_refs to eliminate
any references to the alias *before* we recompile it, not after.
  • Loading branch information
msullivan committed May 7, 2024
1 parent d82fdf8 commit bd846b3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 33 deletions.
12 changes: 6 additions & 6 deletions edb/schema/expraliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@ def _alter_begin(
context: sd.CommandContext,
) -> s_schema.Schema:
if not context.canonical:
schema = self._propagate_if_expr_refs(
schema,
context,
action=self.get_friendly_description(schema=schema),
)

expr = self.get_attribute_value('expr')
is_computable = self._is_computable(self.scls, schema)
if expr:
Expand Down Expand Up @@ -415,12 +421,6 @@ def _alter_begin(
)
)

schema = self._propagate_if_expr_refs(
schema,
context,
action=self.get_friendly_description(schema=schema),
)

return super()._alter_begin(schema, context)


Expand Down
77 changes: 50 additions & 27 deletions tests/test_edgeql_data_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11336,33 +11336,6 @@ async def test_edgeql_migration_globals_01(self):
await self.migrate(schema)
await self.migrate(schema)

async def test_edgeql_migration_dml_rewrites_01(self):
await self.migrate(r"""
type Post {
required title: str;
modified: datetime {
rewrite insert, update using (datetime_of_statement())
}
}
""")
await self.migrate(r"""
type BlogPost {
required title: str;
modified: datetime {
rewrite insert, update using (datetime_of_statement())
}
}
""")
await self.migrate(r"""
type BlogPost {
required title: str;
modified: datetime {
rewrite insert, update using (datetime_of_transaction())
}
}
""")
await self.migrate('')

async def test_edgeql_migration_globals_02(self):
await self.migrate(r"""
global current_user_id -> uuid;
Expand Down Expand Up @@ -11398,6 +11371,56 @@ async def test_edgeql_migration_globals_02(self):
await self.migrate(schema)
await self.migrate(schema)

async def test_edgeql_migration_globals_03(self):
# Test modifying a computed global that is used in an access
# policy on the type it refers to.
await self.migrate(r"""
global cur -> uuid;
global scopes := ((select Foo filter .id = global cur).scopes);
type Foo {
multi scopes: str;
access policy s allow select using ('f' in global scopes);
};
""")
await self.migrate(r"""
global cur -> uuid;
global scopes := (
select (select Foo filter .id = global cur).scopes);
type Foo {
multi scopes: str;
access policy s allow select using ('f' in global scopes);
};
""")

async def test_edgeql_migration_dml_rewrites_01(self):
await self.migrate(r"""
type Post {
required title: str;
modified: datetime {
rewrite insert, update using (datetime_of_statement())
}
}
""")
await self.migrate(r"""
type BlogPost {
required title: str;
modified: datetime {
rewrite insert, update using (datetime_of_statement())
}
}
""")
await self.migrate(r"""
type BlogPost {
required title: str;
modified: datetime {
rewrite insert, update using (datetime_of_transaction())
}
}
""")
await self.migrate('')

async def test_edgeql_migration_policies_and_collections(self):
# An infinite recursion bug with this this was found by accident
# when a number of tests accidentally were in the non isolated test.
Expand Down

0 comments on commit bd846b3

Please sign in to comment.