You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "imtiaznizami (via GitHub)" <gi...@apache.org> on 2024/07/25 06:54:13 UTC

[I] Fatal error when creating a chart from a saved_query via API call [superset]

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

   ### Bug description
   
   This is a repeat of the following: #23189. I am unable to create a chart using `saved_query` following the superset API. It responds with `Fatal error` instead. (using superset version 4.0.2 using docker compose)
   
   
   
   ### How to reproduce the bug
   
   - Create a saved_query
   
   ```
   curl --location 'http://localhost:8088/api/v1/saved_query/' \
   --header 'Authorization: Bearer eyJ...' \
   --header 'X-CSRFToken: ImQ...' \
   --header 'Accept: application/json' \
   --header 'Content-Type: application/json' \
   --header 'Cookie: .eJ...' \
   --data '{
     "db_id": 2,
     "label": "saved_query",
     "schema": "public",
     "sql": "SELECT * from car"
   }
   '
   ```
   
   This gives back
   
   ```
   {
       "id": 11,
       "result": {
           "db_id": 2,
           "description": null,
           "label": "saved_query",
           "schema": "public",
           "sql": "SELECT * from car",
           "template_parameters": null
       }
   }
   ```
   
   - Create the chart
   
   ```
   curl --location 'http://localhost:8088/api/v1/chart/' \
   --header 'Authorization: Bearer eyJ...' \
   --header 'X-CSRFToken: ImQ...' \
   --header 'Accept: application/json' \
   --header 'Content-Type: application/json' \
   --header 'Cookie: .eJ...' \
   --data '{
       "datasource_id": 11,
       "datasource_type": "saved_query",
       "slice_name": "some_name",
       "viz_type": "table"
   }
   '
   ```
   
   This gives back
   
   ```
   {
       "message": "Fatal error"
   }
   ```
   
   **Expected results**
   Curl command to complete successfully with the creation of the chart from the saved query.
   
   **Actual results**
   Curl result is `{"message" : "Fatal error"}`
   
   superset app stacktrace:
   
   ```
   superset_app          | 2024-07-25 06:15:09,186:DEBUG:superset.stats_logger:[stats_logger] (incr) SavedQueryRestApi.post.success
   superset_app          | 2024-07-25 06:15:09,186:DEBUG:superset.stats_logger:[stats_logger] (timing) SavedQueryRestApi.post.time | 21.099509991472587 
   superset_app          | 172.26.0.1 - - [25/Jul/2024:06:15:09 +0000] "POST /api/v1/saved_query/ HTTP/1.1" 201 191 "-" "PostmanRuntime/7.40.0"
   superset_app          | 2024-07-25 06:15:32,776:DEBUG:superset.stats_logger:[stats_logger] (incr) health
   superset_app          | 127.0.0.1 - - [25/Jul/2024:06:15:32 +0000] "GET /health HTTP/1.1" 200 2 "-" "curl/7.88.1"
   superset_app          | 2024-07-25 06:15:47,916:DEBUG:superset.stats_logger:[stats_logger] (incr) ChartRestApi.post.error
   superset_app          | 2024-07-25 06:15:47,917:ERROR:flask_appbuilder.api:'SavedQuery' object has no attribute 'name'
   superset_app          | Traceback (most recent call last):
   superset_app          |   File "/usr/local/lib/python3.10/site-packages/flask_appbuilder/api/__init__.py", line 110, in wraps
   superset_app          |     return f(self, *args, **kwargs)
   superset_app          |   File "/app/superset/views/base_api.py", line 127, in wraps
   superset_app          |     raise ex
   superset_app          |   File "/app/superset/views/base_api.py", line 121, in wraps
   superset_app          |     duration, response = time_function(f, self, *args, **kwargs)
   superset_app          |   File "/app/superset/utils/core.py", line 1470, in time_function
   superset_app          |     response = func(*args, **kwargs)
   superset_app          |   File "/app/superset/utils/log.py", line 255, in wrapper
   superset_app          |     value = f(*args, **kwargs)
   superset_app          |   File "/app/superset/views/base_api.py", line 93, in wraps
   superset_app          |     return f(self, *args, **kwargs)
   superset_app          |   File "/app/superset/charts/api.py", line 329, in post
   superset_app          |     new_model = CreateChartCommand(item).run()
   superset_app          |   File "/app/superset/commands/chart/create.py", line 46, in run
   superset_app          |     self.validate()
   superset_app          |   File "/app/superset/commands/chart/create.py", line 65, in validate
   superset_app          |     self._properties["datasource_name"] = datasource.name
   superset_app          | AttributeError: 'SavedQuery' object has no attribute 'name'
   superset_app          | 172.26.0.1 - - [25/Jul/2024:06:15:47 +0000] "POST /api/v1/chart/ HTTP/1.1" 500 31 "-" "PostmanRuntime/7.40.0"
   ```
   
   Also note that in #23189 the answer by ShaliniIruvuru ([answer](https://github.com/apache/superset/issues/23189#issuecomment-1515875030)) mentions `query` instead of `saved_query` in the chart creation JSON (which should be a different object). 
   
   ### Screenshots/recordings
   
   _No response_
   
   ### Superset version
   
   4.0.2
   
   ### Python version
   
   I don't know
   
   ### Node version
   
   I don't know
   
   ### Browser
   
   Chrome
   
   ### Additional context
   
   Used the following command to create the container:
   
   ```
   export TAG=4.0.2 && docker compose -f docker-compose-image-tag.yml up
   ```
   
   ### 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: notifications-unsubscribe@superset.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "imtiaznizami (via GitHub)" <gi...@apache.org>.
imtiaznizami commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-2249672537

   @dosu As mentioned in my original post, I am using 4.0.2 which is more recent than 4.0.0 suggested by you. Also, the issue you referenced has 4.0.2 label as well.


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-5405174733

   This one's been open too long, looking into it now...


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-4035378123

   This continues to be reported. If anyone can provide a minimal reproduction — a SQL query body, chart type, and the exact API call — that would help narrow down the root cause. A pivot table connection seems plausible based on recent comments.


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-2249741513

   <!-- Answer -->
   To resolve the issue of creating a chart from a `saved_query` via an API call in Superset version 4.0.2, you need to ensure that the backend correctly handles `saved_query` objects. The error you're encountering (`'SavedQuery' object has no attribute 'name'`) indicates that the `SavedQuery` object is missing the `name` attribute, which is expected by the `CreateChartCommand`.
   
   Here are the steps to modify the backend to support `saved_query`:
   
   1. **Modify the `CreateChartCommand` to handle `saved_query`**:
      Update the `validate` method in `CreateChartCommand` to correctly handle `saved_query` objects. Specifically, you need to extract the necessary information from the `SavedQuery` object.
   
      ```python
      def validate(self) -> None:
          exceptions = []
          datasource_type = self._properties["datasource_type"]
          datasource_id = self._properties["datasource_id"]
          dashboard_ids = self._properties.get("dashboards", [])
          owner_ids: Optional[list[int]] = self._properties.get("owners")
   
          # Validate/Populate datasource
          try:
              datasource = get_datasource_by_id(datasource_id, datasource_type)
              if datasource_type == "saved_query":
                  self._properties["datasource_name"] = datasource.label
              else:
                  self._properties["datasource_name"] = datasource.name
          except ValidationError as ex:
              exceptions.append(ex)
   
          # Validate/Populate dashboards
          dashboards = DashboardDAO.find_by_ids(dashboard_ids)
          if len(dashboards) != len(dashboard_ids):
              exceptions.append(DashboardsNotFoundValidationError())
          for dash in dashboards:
              if not security_manager.is_owner(dash):
                  raise DashboardsForbiddenError()
          self._properties["dashboards"] = dashboards
   
          try:
              owners = self.populate_owners(owner_ids)
              self._properties["owners"] = owners
          except ValidationError as ex:
              exceptions.append(ex)
          if exceptions:
              raise ChartInvalidError(exceptions=exceptions)
      ```
   
   2. **Ensure `get_datasource_by_id` supports `saved_query`**:
      The `get_datasource_by_id` function already supports `saved_query` as a datasource type, so no changes are needed here <sup>[[1]](https://github.com/apache/superset/blob/master/superset/daos/datasource.py)</sup>.
   
   3. **Update the frontend if necessary**:
      Ensure that the frontend correctly handles the `saved_query` type when creating charts. This involves making sure that the `fetchSlices` function and `parseResult` function correctly process `saved_query` objects <sup>[[2]](https://github.com/apache/superset/blob/master/superset-frontend/src/dashboard/actions/sliceEntities.ts)</sup>.
   
   By making these changes, you should be able to create charts from `saved_query` objects without encountering the fatal error.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-2249604784

   <!-- Greeting -->
   Hello, @imtiaznizami! I'm here to help you with any bugs, questions, or contributions you have for the repository. Let me know how I can assist you!
   
   <!-- Answer -->
   To resolve the fatal error when trying to create a chart from a `saved_query` via an API call in Superset version 4.0.2 using Docker Compose, you should apply the fix provided in the pull request [#27644](https://github.com/apache/superset/pull/27644). This fix provides more inclusive error handling for saved queries.
   
   Here is the relevant change from the pull request:
   
   ```md
   - [#27644](https://github.com/apache/superset/pull/27644) fix: Provide more inclusive error handling for saved queries (@john-bodley)
   ```
   
   Ensure that your Superset instance includes this fix by updating to the latest version that includes this pull request or manually applying the changes from the pull request to your local instance <sup>[[1]](https://github.com/apache/superset/blob/master/CHANGELOG/4.0.0.md)</sup>.
   
   ### Steps to Update Superset to Include the Fix
   
   1. **Backup Your Data**: Before performing any upgrade, ensure you have a backup of your current Superset data and configuration.
   
   2. **Update Superset**:
      - If you are using pip, you can update Superset by running:
        ```bash
        pip install apache-superset==4.0.0
        ```
      - If you are using Docker, update your `docker-compose.yml` to use the new version:
        ```yaml
        version: '3.1'
        services:
          superset:
            image: apache/superset:4.0.0
            ...
        ```
        Then, pull the new image and restart the services:
        ```bash
        docker-compose pull
        docker-compose up -d
        ```
   
   3. **Run Database Migrations**: After updating the Superset version, you need to run the database migrations to ensure your database schema is up-to-date:
      ```bash
      superset db upgrade
      ```
   
   4. **Restart Superset**: Finally, restart the Superset service to apply the changes:
      ```bash
      superset run
      ```
   
   By following these steps, you will update Superset to version 4.0.0, which includes the fix from pull request [#27644](https://github.com/apache/superset/pull/27644) <sup>[[1]](https://github.com/apache/superset/blob/master/CHANGELOG/4.0.0.md)</sup>.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "imtiaznizami (via GitHub)" <gi...@apache.org>.
imtiaznizami commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-2249714359

   @dosu
   The data-source table should have completely different IDs than data-source saved_queries.
   
   However, I tried your suggestion, and the chart was created with an entirely different set of columns (which compliments what I wrote above).


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "KahaanD (via GitHub)" <gi...@apache.org>.
KahaanD commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-2972575273

   Facing the same issue; Any resolution to this? I suspect it might have something to do with Pivoted Tables


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-2249686852

   <!-- Answer -->
   To resolve the fatal error when trying to create a chart from a `saved_query` via an API call in Superset version 4.0.2, you should use `datasource_type` as `table` instead of `saved_query`. This workaround has been suggested in a similar issue and should help you avoid the error <sup>[[1]](https://github.com/apache/superset/issues/23189)</sup>.
   
   Here is the modified curl command for creating the chart:
   
   ```bash
   curl --location 'http://localhost:8088/api/v1/chart/' \
   --header 'Authorization: Bearer eyJ...' \
   --header 'X-CSRFToken: ImQ...' \
   --header 'Accept: application/json' \
   --header 'Content-Type: application/json' \
   --header 'Cookie: .eJ...' \
   --data '{
       "datasource_id": 11,
       "datasource_type": "table",
       "slice_name": "some_name",
       "viz_type": "table"
   }'
   ```
   
   This should help you create the chart successfully.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "imtiaznizami (via GitHub)" <gi...@apache.org>.
imtiaznizami commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-2254329173

   This did not work. I am getting the same error.


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "endimonan (via GitHub)" <gi...@apache.org>.
endimonan commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-5315305578

   Hello @rusackas 
   
   <img width="722" height="572" alt="Image" src="https://github.com/user-attachments/assets/c933ce16-3c94-44a7-9ac2-0af742d4f7d7" />
   
   After some tests I can reproduce that, seems to be a real issue. I think we can either add e2e chart support for saved_query or remove it from the chart API's accepted datasource types. What do you think? 
   
   Cheers


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-5124442598

   Circling back since nobody's landed a minimal repro yet. @KahaanD, if pivot tables are involved for you, could you share the exact chart type, a sample `sql` body, and the API call you're making? That'd be enough to actually chase this down.
   
   This might be closed due to lack of engagement if we can't get a clear repro.


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-2776760565

   Sorry the bot didn't help, but this has slid under the radar and been silent for quite a long time. Are you still facing this issue? Maybe it's better in 4.1.2/5.0.0?


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on issue #29697:
URL: https://github.com/apache/superset/issues/29697#issuecomment-5405328567

   Thanks @endimonan, the minimal repro was exactly what was needed to pin this down.
   
   Root cause: `Slice.datasource` only ever resolves the `table` relationship, so `datasource_type: "saved_query"` was always going to be a dead end — `SavedQuery` has no `.name` attribute, which is what crashes with the 500. `datasource_type: "query"` has the same underlying problem but doesn't crash (Query has an unrelated `.name` property used for CTAS naming), it just silently creates a chart that can never render.
   
   Given how deep the "not actually wired up" gap goes (this isn't just the `.name` line — there's no code path that can query a saved_query/query-backed chart at all), went with your second option: reject both at chart create/update time with a clean 422 instead of the opaque 500, rather than trying to build out full e2e support for something charts were never actually plumbed to do.
   
   PR: #43500


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] Fatal error when creating a chart from a saved_query via API call [superset]

Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe closed issue #29697: Fatal error when creating a chart from a saved_query via API call
URL: https://github.com/apache/superset/issues/29697


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org