torzsmokus opened a new issue, #32879:
URL: https://github.com/apache/superset/issues/32879

   ### Bug description
   
   **TL;DR:** Please **update field name handling so that an SQL field with 
multiple spaces in its name is handled correctly**.  If that is not trivial, 
please update the error message to help the user find the issue and fix it 
using the CUSTOM SQL feature.
   
   ---
   ### Steps to reproduce
   
   1.  Set up a Superset instance with MS SQL support (pymysql).
   2. Add a data source where the table has column names with multiple spaces.
   3. Start setting up a chart with those columns.
   
   ### Expected result
   Can use all table columns in the chart.
   
   ### Actual result
   Error: _Custom SQL fields cannot contain sub-queries._
   
   
   ### Screenshots/recordings
   
   ### Problem:
   
![Image](https://github.com/user-attachments/assets/b993175b-ff7c-4f20-8677-d265b9fb965a)
   
   ### Solution:
   
![Image](https://github.com/user-attachments/assets/865a77d5-e0d5-4b61-81d1-7f695c7fc6d5)
   
   
   ### Superset version
   
   4.1.2
   
   ### Python version
   
   I don't know
   
   ### Node version
   
   I don't know
   
   ### Browser
   
   Chrome
   
   ### Additional context
   
   
   ### Story
   As a newcomer to superset, I tried to set up my very first chart, just to 
get the cryptic error message _Custom SQL fields cannot contain sub-queries._
   
   Googling for that message, I found myself in a rabbit hole with suggestions 
like use a feature flag (a _what?_) that weakens security (smh). I felt 
something was not right, I just wanted to display a very simple dataset (from a 
MS SQL Server table) without any subqueries or other magic. Then, buried deep 
in an old but necromanced discussion #23574 , I found the actual issue: [my 
field names have 
spaces](https://github.com/apache/superset/discussions/23574#discussioncomment-11568639),
 and [I need to quote them according to the SQL flavour of my data source using 
the CUSTOM SQL 
feature](https://github.com/apache/superset/discussions/23574#discussioncomment-11853532)
 to be able to use them as columns (dimensions): 
   
   Fields with only one space in its name needed no fix in my case, just the 
one(s) with more than one space.
   
   ### Remarks
   
   _My superset version is actually 4.1.1, not 4.1.2 (that one is not in the 
[helm repo](https://artifacthub.io/packages/helm/superset/superset) yet)_
   
   This is almost, but _not quite a duplicate_ of 
https://github.com/apache/superset/issues/25072 as I do not use any special 
queries.
   
   
   <details><summary>Stack trace</summary>
   
   ```
   2025-03-27 
09:50:38,407:WARNING:superset.views.error_handling:SupersetErrorException
   Traceback (most recent call last):
     File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1484, in 
full_dispatch_request
       rv = self.dispatch_request()
     File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1469, in 
dispatch_request
       return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
     File 
"/usr/local/lib/python3.10/site-packages/flask_appbuilder/security/decorators.py",
 line 95, in wraps
       return f(self, *args, **kwargs)
     File "/app/superset/views/base_api.py", line 119, in wraps
       duration, response = time_function(f, self, *args, **kwargs)
     File "/app/superset/utils/core.py", line 1364, in time_function
       response = func(*args, **kwargs)
     File "/app/superset/utils/log.py", line 303, in wrapper
       value = f(*args, **kwargs)
     File "/app/superset/charts/data/api.py", line 260, in data
       return self._get_data_response(
     File "/app/superset/charts/data/api.py", line 416, in _get_data_response
       result = command.run(force_cached=force_cached)
     File "/app/superset/commands/chart/data/get_data_command.py", line 45, in 
run
       payload = self._query_context.get_payload(
     File "/app/superset/common/query_context.py", line 102, in get_payload
       return self._processor.get_payload(cache_query_context, force_cached)
     File "/app/superset/common/query_context_processor.py", line 675, in 
get_payload
       query_results = [
     File "/app/superset/common/query_context_processor.py", line 676, in 
<listcomp>
       get_query_results(
     File "/app/superset/common/query_actions.py", line 227, in 
get_query_results
       return result_func(query_context, query_obj, force_cached)
     File "/app/superset/common/query_actions.py", line 103, in _get_full
       payload = query_context.get_df_payload(query_obj, 
force_cached=force_cached)
     File "/app/superset/common/query_context.py", line 123, in get_df_payload
       return self._processor.get_df_payload(
     File "/app/superset/common/query_context_processor.py", line 158, in 
get_df_payload
       query_result = self.get_query_result(query_obj)
     File "/app/superset/common/query_context_processor.py", line 237, in 
get_query_result
       result = query_context.datasource.query(query_object.to_dict())
     File "/app/superset/connectors/sqla/models.py", line 1729, in query
       query_str_ext = self.get_query_str_extended(query_obj)
     File "/app/superset/models/helpers.py", line 880, in get_query_str_extended
       sqlaq = self.get_sqla_query(**query_obj)
     File "/app/superset/models/helpers.py", line 1653, in get_sqla_query
       selected = validate_adhoc_subquery(
     File "/app/superset/models/helpers.py", line 138, in 
validate_adhoc_subquery
       raise SupersetSecurityException(
   superset.exceptions.SupersetSecurityException: Custom SQL fields cannot 
contain sub-queries.
   ```
   </details> 
   
   ### Checklist
   
   - [x] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [x] 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to