apache / superset

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

AttributeError: 'Template' object has no attribute 'strip' #29940

Closed MEclipse1 closed 3 months ago

MEclipse1 commented 3 months ago

Screenshot

image

Description

2024-08-14 11:39:14,348:ERROR:marvel.views.error_handling:'Template' object has no attribute 'strip' Traceback (most recent call last): File "e:\project\marvel\marvel\views\error_handling.py", line 84, in wraps return f(self, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^ File "e:\project\marvel\marvel\views\base_api.py", line 447, in get_list_headless duration, response = time_function(super().get_list_headless, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "e:\project\marvel\marvel\utils\core.py", line 1348, in time_function response = func(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\dabu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask_appbuilder\api__init__.py", line 1629, in get_list_headless response[API_RESULT_RES_KEY] = list_model_schema.dump(lst, many=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\dabu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\marshmallow\schema.py", line 549, in dump result = self._serialize(processed_obj, many=many) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\dabu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\marshmallow\schema.py", line 511, in _serialize return [ ^ File "C:\Users\dabu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\marshmallow\schema.py", line 512, in self._serialize(d, many=False) File "C:\Users\dabu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\marshmallow\schema.py", line 517, in _serialize value = field_obj.serialize(attr_name, obj, accessor=self.get_attribute) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\dabu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\marshmallow\fields.py", line 341, in serialize return self._serialize(value, attr, obj, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\dabu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\marshmallow\fields.py", line 1985, in _serialize return self._serialize_method(obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "e:\project\marvel\marvel\queries\schemas.py", line 60, in get_sql_tables return obj.sql_tables ^^^^^^^^^^^^^^ File "e:\project\marvel\marvel\models\sql_lab.py", line 67, in sql_tables extract_tables_from_jinja_sql( File "e:\project\marvel\marvel\sql_parse.py", line 1609, in extract_tables_from_jinja_sql | ParsedQuery( ^^^^^^^^^^^^ File "e:\project\marvel\marvel\sql_parse.py", line 735, in init self._parsed = sqlparse.parse(self.stripped()) ^^^^^^^^^^^^^^^ File "e:\project\marvel\marvel\sql_parse.py", line 1015, in stripped return self.sql.strip(" \t\r\n;") ^^^^^^^^^^^^^^ AttributeError: 'Template' object has no attribute 'strip'

dosubot[bot] commented 3 months ago

Hey there, @MEclipse1! I'm here to assist you with any bugs, questions, or contributions you have. Let's tackle this together! 🤖

To resolve the AttributeError: 'Template' object has no attribute 'strip' issue, you need to ensure that the stripped attribute is accessed correctly. The stripped method should be accessed as an attribute, not as a method.

Here is the corrected code snippet:

rendered_query = sql_template_processor.process_template(
    parsed_query.stripped, **execution_context.template_params
)

Additionally, ensure that the parsed_query object is correctly instantiated and that the stripped attribute is properly defined within the ParsedQuery class. This change should resolve the AttributeError you are encountering.

Refer to the superset/models/sql_lab.py file for more context on how SQL parsing and template processing are handled in Apache Superset. The process_template method in the BaseTemplateProcessor class is responsible for processing SQL templates, and it uses the Jinja environment to render the templates. Make sure your parsed_query object and its attributes are compatible with this method [1][2][3][4].

To continue talking to Dosu, mention @dosu.

sfirke commented 3 months ago

It would help if you followed the bug report template and included the version of Superset you're using, etc.

This looks like a duplicate of https://github.com/apache/superset/issues/28145, what do you think?

MEclipse1 commented 3 months ago

It would help if you followed the bug report template and included the version of Superset you're using, etc.

This looks like a duplicate of #28145, what do you think?

That helped. Thanks a lot!