Skip to content
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

KeyError: 'sql' when opening a Trino virtual dataset that contains latest_partition on SQL Lab #30338

Closed
3 tasks done
michael-s-molina opened this issue Sep 19, 2024 · 0 comments · Fixed by #30339
Closed
3 tasks done
Assignees
Labels
data:connect:trino Related to Trino sqllab Namespace | Anything related to the SQL Lab

Comments

@michael-s-molina
Copy link
Member

Bug description

Every time I try to open, in SQL Lab from Explore, a virtual dataset that contains WHERE time_column <= '{{presto.latest_partition('table_name')}}' it throws a DB engine Error with the following stacktrace:

/apache-superset/superset/utils/decorators.py:263: SAWarning: Session's state has been changed on a non-active transaction - this state will be discarded.
  db.session.rollback()  # pylint: disable=consider-using-transaction
2024-09-19 14:04:59,932:warning:superset.views.error_handling:Exception
Traceback (most recent call last):
  File "/apache-superset/superset/commands/sql_lab/execute.py", line 106, in run
    status = self._run_sql_json_exec_from_scratch()
  File "/apache-superset/superset/commands/sql_lab/execute.py", line 161, in _run_sql_json_exec_from_scratch
    return self._sql_json_executor.execute(
  File "/apache-superset/superset/sqllab/sql_json_executer.py", line 170, in execute
    query_id = execution_context.query.id
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/attributes.py", line 487, in __get__
    return self.impl.get(state, dict_)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/attributes.py", line 959, in get
    value = self._fire_loader_callables(state, key, passive)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/attributes.py", line 990, in _fire_loader_callables
    return state._load_expired(state, passive)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/state.py", line 712, in _load_expired
    self.manager.expired_attribute_loader(self, toload, passive)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/loading.py", line 1451, in load_scalar_attributes
    result = load_on_ident(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/loading.py", line 407, in load_on_ident
    return load_on_pk_identity(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/loading.py", line 530, in load_on_pk_identity
    session.execute(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 1665, in execute
    ) = compile_state_cls.orm_pre_session_exec(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/context.py", line 312, in orm_pre_session_exec
    session._autoflush()
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 2253, in _autoflush
    self.flush()
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 3449, in flush
    self._flush(objects)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 3588, in _flush
    with util.safe_reraise():
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/session.py", line 3549, in _flush
    flush_context.execute()
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/persistence.py", line 237, in save_obj
    _emit_update_statements(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/persistence.py", line 886, in _emit_update_statements
    for (
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/persistence.py", line 612, in _collect_update_commands
    value = state_dict[propkey]
KeyError: 'sql'

The exception only happens if latest_partition is used. If you click on Run query again, the query executes.

How to reproduce the bug

  1. From Explore open a virtual dataset on SQL Lab (Trino)
  2. You'll see a DB Engine error
  3. Run the query again
  4. It works

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

Also present in 4.1.0 RC2

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
@dosubot dosubot bot added data:connect:trino Related to Trino sqllab Namespace | Anything related to the SQL Lab labels Sep 19, 2024
@michael-s-molina michael-s-molina self-assigned this Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:connect:trino Related to Trino sqllab Namespace | Anything related to the SQL Lab
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant