Titan-Systems/titan

KeyError: 'view' when calling bp.plan() with FutureGrant using on_future_views_in

bjorhn opened this issue · 4 comments

When I call bp.plan() after adding a future grant for all tables (or views, this applies to both) in a schema, titan raises a KeyError exception.

My FutureGrant:

grant = FutureGrant(priv="SELECT", on_future_views_in=Schema(name="SOME_DB.MY_SCHEMA"), to="MY_ROLE")
resources.append(grant)

The exception:

│ /home/vscode/.cache/pypoetry/virtualenvs/full/lib/python3.11/site-packages/titan/resources/resou │
│ rce.py:124 in get_metadata                                                                       │
│                                                                                                  │
│   121 │                                                                                          │
│   122 │   @classmethod                                                                           │
│   123 │   def get_metadata(cls, field_name: str):                                                │
│ ❱ 124 │   │   return {f.name: f.metadata for f in fields(cls)}[field_name]                       │
│   125                                                                                            │
│   126                                                                                            │
│   127 RESOURCE_SCOPES = {                                                                        │
│                                                                                                  │
│ ╭───────────────────────── locals ──────────────────────────╮                                    │
│ │        cls = <class 'titan.resources.grant._FutureGrant'> │                                    │
│ │ field_name = 'view'                                       │                                    │
│ ╰───────────────────────────────────────────────────────────╯ 

If necessary, I could put together a minimal example program showcasing the problem.

teej commented

Can you try this again with the most recent version (>=0.4.0)?

Hello, I'm not sure if this is the same issue but using the above code I received the following error.

grant = FutureGrant(priv="SELECT", on_future_views_in=Schema(name="some_db.some_schema"), to="SOME_DB_SOME_SCHEMA_READ_ONLY_AR")
bp = Blueprint(name="roles")
    bp.add(grant)
    plan = bp.plan(session)
    pprint(plan)

Output

>>> pprint(plan)
[ResourceChange(action=<Action.ADD: 'add'>,
                urn=URN(urn::#########:future_grant/SOME_DB_SOME_SCHEMA_READ_ONLY_AR?priv=SELECT&on=schema/SOME_DB.SOME_SCHEMA.<VIEW>),
                before={},
                after={'view': ['SELECT']},
                delta={'view': ['SELECT']})]

>>> bp.apply(session, plan)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "venv/lib/python3.10/site-packages/titan/blueprint.py", line 663, in apply
    action_queue = self._compile_plan_to_sql(session_ctx, plan)
  File "venv/lib/python3.10/site-packages/titan/blueprint.py", line 740, in _compile_plan_to_sql
    _queue_change(change)
  File "venv/lib/python3.10/site-packages/titan/blueprint.py", line 728, in _queue_change
    action = lifecycle.create_resource(change.urn, change.after, props)
  File "venv/lib/python3.10/site-packages/titan/lifecycle.py", line 22, in create_resource
    return getattr(__this__, f"create_{urn.resource_label}", create__default)(urn, data, props, if_not_exists)
  File "venv/lib/python3.10/site-packages/titan/lifecycle.py", line 74, in create_future_grant
    on_type = data["on_type"]
KeyError: 'on_type'
teej commented

This issue is fixed in the current version, please upgrade with

python -m pip install --upgrade git+https://github.com/Titan-Systems/titan.git

This issue is fixed in the current version, please upgrade with

python -m pip install --upgrade git+https://github.com/Titan-Systems/titan.git

I'm still getting the same error, I removed titan and reinstalled it

Successfully installed titan-0.6.0