apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
62.97k stars 13.94k forks source link

Errors importing datasets with TAGGING_SYSTEM enabled #28020

Open bmtcril opened 7 months ago

bmtcril commented 7 months ago

Bug description

When importing a dataset on the command line we consistently run into the error as described in #24528 . The problem seems to be that dataset isn't included in the enum on the taggable_objects table. So far the only workaround has been to turn off the TAGGING_SYSTEM feature flag.

How to reproduce the bug

  1. Export a functioning dashboard with a dataset attached
  2. Import the dashboard using superset.examples.utils.load_configs_from_directory
  3. See the error MySQLdb._exceptions.DataError: (1265, "Data truncated for column 'object_type' at row 1")

Screenshots/recordings

No response

Superset version

4.0.0

Python version

3.9

Node version

16

Browser

Not applicable

Additional context

Note the attempt to insert "dataset" into tagged_object at the bottom of the stack:

2024-04-12 20:28:53,083:INFO:superset.models.helpers:Updating tables reporting.int_problem_results
/app/superset/models/helpers.py:307: SAWarning: transaction already deassociated from connection
  obj = obj_query.one_or_none()
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1819, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
  File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/lib/python3.10/site-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.DataError: (1265, "Data truncated for column 'object_type' at row 1")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/superset/commands/importers/v1/examples.py", line 71, in run
    self._import(
  File "/app/superset/commands/importers/v1/examples.py", line 131, in _import
    dataset = import_dataset(
  File "/app/superset/commands/dataset/importers/v1/utils.py", line 151, in import_dataset
    dataset = SqlaTable.import_from_dict(config, recursive=True, sync=sync)
  File "/app/superset/models/helpers.py", line 343, in import_from_dict
    child_class.import_from_dict(
  File "/app/superset/models/helpers.py", line 307, in import_from_dict
    obj = obj_query.one_or_none()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2845, in one_or_none
    return self._iter().one_or_none()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2903, in _iter
    result = self.session.execute(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1644, in execute
    ) = compile_state_cls.orm_pre_session_exec(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/context.py", line 319, in orm_pre_session_exec
    session._autoflush()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2241, in _autoflush
    util.raise_(e, with_traceback=sys.exc_info()[2])
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2230, in _autoflush
    self.flush()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3367, in flush
    self._flush(objects)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3506, in _flush
    with util.safe_reraise():
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3467, in _flush
    flush_context.execute()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 253, in save_obj
    _finalize_insert_update_commands(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 1568, in _finalize_insert_update_commands
    mapper.dispatch.after_update(mapper, connection, state)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/event/attr.py", line 343, in __call__
    fn(*args, **kw)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/events.py", line 743, in wrap
    fn(*arg, **kw)
  File "/app/superset/tags/models.py", line 274, in after_update
    session.commit()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1435, in commit
    self._transaction.commit(_to_root=self.future)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 829, in commit
    self._prepare_impl()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 808, in _prepare_impl
    self.session.flush()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3367, in flush
    self._flush(objects)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3506, in _flush
    with util.safe_reraise():
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3467, in _flush
    flush_context.execute()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 245, in save_obj
    _emit_insert_statements(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 1238, in _emit_insert_statements
    result = connection._execute_20(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1631, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 325, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1498, in _execute_clauseelement
    ret = self._execute_context(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1862, in _execute_context
    self._handle_dbapi_exception(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2043, in _handle_dbapi_exception
    util.raise_(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1819, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
  File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/lib/python3.10/site-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)
sqlalchemy.exc.DataError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely)
(MySQLdb._exceptions.DataError) (1265, "Data truncated for column 'object_type' at row 1")
[SQL: INSERT INTO tagged_object (created_on, changed_on, tag_id, object_id, object_type, created_by_fk, changed_by_fk) VALUES (%s, %s, %s, %s, %s, %s, %s)]
[parameters: (datetime.datetime(2024, 4, 12, 20, 28, 53, 100714), datetime.datetime(2024, 4, 12, 20, 28, 53, 100722), 3, 505, 'dataset', None, None)]

Checklist

Ian2012 commented 7 months ago

@rusackas We have experienced this issue in two different Superset installations. Our MySQL version is 8.1.0

rubenandre commented 6 months ago

We're experiencing the same issue using Postgres 16.1 on superset 4.0.X

nkdanta1 commented 2 months ago

We are also experiencing the same issue. Is there any workaround apart from turning off the TAGGING_SYSTEM feature flag?

nkdanta1 commented 2 months ago

I was able to fix it after commenting below lines in superset/tags/core.py file.

  sqla.event.listen(SqlaTable, "after_insert", DatasetUpdater.after_insert)
  sqla.event.listen(SqlaTable, "after_update", DatasetUpdater.after_update)
  sqla.event.listen(SqlaTable, "after_delete", DatasetUpdater.after_delete)