Bug description
Server logs:
| ERROR:flask_appbuilder.api:Tag could not be created.
superset | Traceback (most recent call last):
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
superset | self.dialect.do_execute(
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
superset | cursor.execute(statement, parameters)
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/cursors.py", line 153, in execute
superset | result = self._query(query)
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/cursors.py", line 322, in _query
superset | conn.query(q)
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/connections.py", line 563, in query
superset | self._affected_rows = self._read_query_result(unbuffered=unbuffered)
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/connections.py", line 825, in _read_query_result
superset | result.read()
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/connections.py", line 1199, in read
superset | first_packet = self.connection._read_packet()
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/connections.py", line 775, in _read_packet
superset | packet.raise_for_error()
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/protocol.py", line 219, in raise_for_error
superset | err.raise_mysql_exception(self._data)
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/err.py", line 150, in raise_mysql_exception
superset | raise errorclass(errno, errval)
superset | pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''keep_template_dashboards', 'custom', NULL, 1, 1)' at line 1")
superset |
superset | The above exception was the direct cause of the following exception:
superset |
superset | Traceback (most recent call last):
superset | File "/app/superset/utils/decorators.py", line 259, in wrapped
superset | result = func(*args, **kwargs)
superset | File "/app/superset/commands/tag/create.py", line 78, in run
superset | tag = TagDAO.get_by_name(tag_name.strip(), TagType.custom)
superset | File "/app/superset/daos/tag.py", line 131, in get_by_name
superset | tag = get_tag(name, db.session, type_)
superset | File "/app/superset/tags/models.py", line 143, in get_tag
superset | session.commit()
superset | File "<string>", line 2, in commit
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1454, in commit
superset | self._transaction.commit(_to_root=self.future)
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 832, in commit
superset | self._prepare_impl()
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 811, in _prepare_impl
superset | self.session.flush()
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3449, in flush
superset | self._flush(objects)
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3588, in _flush
superset | with util.safe_reraise():
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
superset | compat.raise_(
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
superset | raise exception
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3549, in _flush
superset | flush_context.execute()
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
superset | rec.execute(self)
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
superset | util.preloaded.orm_persistence.save_obj(
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 245, in save_obj
superset | _emit_insert_statements(
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 1238, in _emit_insert_statements
superset | result = connection._execute_20(
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1710, in _execute_20
superset | return meth(self, args_10style, kwargs_10style, execution_options)
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 334, in _execute_on_connection
superset | return connection._execute_clauseelement(
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1577, in _execute_clauseelement
superset | ret = self._execute_context(
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1953, in _execute_context
superset | self._handle_dbapi_exception(
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2134, in _handle_dbapi_exception
superset | util.raise_(
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
superset | raise exception
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
superset | self.dialect.do_execute(
superset | File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
superset | cursor.execute(statement, parameters)
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/cursors.py", line 153, in execute
superset | result = self._query(query)
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/cursors.py", line 322, in _query
superset | conn.query(q)
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/connections.py", line 563, in query
superset | self._affected_rows = self._read_query_result(unbuffered=unbuffered)
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/connections.py", line 825, in _read_query_result
superset | result.read()
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/connections.py", line 1199, in read
superset | first_packet = self.connection._read_packet()
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/connections.py", line 775, in _read_packet
superset | packet.raise_for_error()
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/protocol.py", line 219, in raise_for_error
superset | err.raise_mysql_exception(self._data)
superset | File "/app/superset_home/.local/lib/python3.10/site-packages/pymysql/err.py", line 150, in raise_mysql_exception
superset | raise errorclass(errno, errval)
superset | sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''keep_template_dashboards', 'custom', NULL, 1, 1)' at line 1")
superset | [SQL: INSERT INTO tag (created_on, changed_on, name, type, description, created_by_fk, changed_by_fk) VALUES (%(created_on)s, %(changed_on)s, %(name)s, %(type)s, %(description)s, %(created_by_fk)s, %(changed_by_fk)s)]
superset | [parameters: {'created_on': datetime.datetime(2025, 3, 3, 13, 11, 16, 346554), 'changed_on': datetime.datetime(2025, 3, 3, 13, 11, 16, 346561), 'name': Markup('keep_template_dashboards'), 'type': 'custom', 'description': None, 'created_by_fk': 1, 'changed_by_fk': 1}]
Screenshots/recordings
No response
Superset version
master / latest-dev
Python version
3.9
Node version
16
Browser
Chrome
Additional context
No response
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.
Comment From: dosubot[bot]
The error you're encountering seems to be related to a SQL syntax issue when creating a tag in Superset with MySQL. The error message indicates a problem with the SQL syntax near the name
field, which is being passed as a Markup
object. This could be causing the syntax error because MySQL might not be handling the Markup
object correctly.
Here are a few steps you can take to troubleshoot and potentially resolve this issue:
-
Check the
Markup
Usage: Ensure that thename
field is being passed as a plain string rather than aMarkup
object. TheMarkup
class might be adding HTML-like encoding that MySQL doesn't interpret correctly. You can modify the code to convert theMarkup
object to a string before passing it to the SQL query. -
Review SQLAlchemy and MySQL Compatibility: Make sure that your SQLAlchemy version is compatible with the MySQL version you are using. There might be specific configurations or settings needed to handle certain data types or encodings.
-
SQLAlchemy Exception Handling: Superset's codebase includes specific handlers for MySQL syntax errors. Ensure that these handlers are correctly implemented and that any custom error messages are being logged for further analysis [1].
-
Test with a Simple Tag Name: Try creating a tag with a simple name (e.g., "test_tag") to see if the issue persists. This can help determine if the problem is related to specific characters or encodings in the tag name.
-
Database Logs: Check the MySQL server logs for any additional information or context about the syntax error. This might provide more insight into what MySQL is expecting.
By addressing these areas, you should be able to identify the root cause of the syntax error and implement a solution.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
Comment From: shahargl
I've managed to make it work by patching this line of code:
FROM apache/superset
RUN sed -i 's/tag = Tag(name=escape(tag_name), type=type_)/tag = Tag(name=tag_name, type=type_)/' /app/superset/tags/models.py
Comment From: rusackas
Hey @shahargl - would you be willing to open up a pull request on the repo? Then we could officially close the issue and everyone wins! Holler if you would need/want any help with the process.
Comment From: shahargl
yes, sure. will do it tomorrow.
Comment From: rusackas
@shahargl still interested/willing to open a PR if it's still relevant? Otherwise, we can just close this out, since it seems most people aren't running into this (somehow).