Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tablemodelview] Fixing JSON api/read serializable issue #6023

Conversation

john-bodley
Copy link
Member

This PR resolves an issue with tablemodelview/api/read which throws the following exception,

TypeError: Object of type Database is not JSON serializable

i.e., it's trying to to serialize the Database object to JSON which is defined as one of the FAB list_columns. The remedy is to simply reference the Database.name attribute as opposed to the Database object.

Attached is a screenshot, note I've kept the label unchanged so the UI remains unchanged:

screenshot

and here's the corresponding API response (truncated):

{
  "count": 11, 
  "label_columns": {
    "cache_timeout": "Cache Timeout", 
    "changed_by": "Changed By", 
    "changed_by_": "Changed By", 
    "changed_by_fk": "Changed By Fk", 
    "changed_on": "Changed On", 
    "changed_on_": "Last Changed", 
    "columns": "Columns", 
    "created_by": "Created By", 
    "created_by_fk": "Created By Fk", 
    "created_on": "Created On", 
    "database": "Database", 
    "database_id": "Database Id", 
    "database_name": "Database", 
    "default_endpoint": "Default Endpoint", 
    "description": "Description", 
    "fetch_values_predicate": "Fetch Values Predicate", 
    "filter_select_enabled": "Enable Filter Select", 
    "id": "Id", 
    "is_featured": "Is Featured", 
    "is_sqllab_view": "SQL Lab View", 
    "link": "Table", 
    "main_dttm_col": "Main Datetime Column", 
    "metrics": "Metrics", 
    "modified": "Modified", 
    "offset": "Offset", 
    "owner": "Owner", 
    "params": "Params", 
    "perm": "Perm", 
    "schema": "Schema", 
    "slices": "Associated Charts", 
    "sql": "Sql", 
    "table_name": "Table Name", 
    "template_params": "Template parameters", 
    "user_id": "User Id"
  }, 
  "list_columns": [
    "link", 
    "database_name", 
    "changed_by_", 
    "modified"
  ], 
  "modelview_name": "TableModelView", 
  "order_columns": [
    "modified"
  ], 
  "page": null, 
  "page_size": null, 
  "pks": [
    1, 
    2, 
    3, 
    4, 
    5, 
    6, 
    7, 
    8, 
    9, 
    10, 
    11
  ], 
  "result": [
    {
      "changed_by_": "", 
      "database_name": "main", 
      "link": "<a target=\"_blank\" href=\"/superset/explore/table/1/\">energy_usage</a>", 
      "modified": "an hour ago"
    }, 
   ...

to: @michellethomas @mistercrunch
cc: @graceguo-supercat @timifasubaa

@pierrelafortune
Copy link

this is awesome thank you!!! 🚀

@john-bodley john-bodley force-pushed the john-bodley-fix-tablemodelview-api-read branch from 45fc3ee to c053f75 Compare October 2, 2018 22:02
@john-bodley john-bodley force-pushed the john-bodley-fix-tablemodelview-api-read branch from c053f75 to 548b88c Compare October 5, 2018 20:44
@codecov-io
Copy link

codecov-io commented Oct 5, 2018

Codecov Report

Merging #6023 into master will increase coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6023      +/-   ##
==========================================
+ Coverage   77.73%   77.85%   +0.11%     
==========================================
  Files          46       46              
  Lines        9398     9400       +2     
==========================================
+ Hits         7306     7318      +12     
+ Misses       2092     2082      -10
Impacted Files Coverage Δ
superset/connectors/sqla/views.py 64.34% <ø> (ø) ⬆️
superset/connectors/sqla/models.py 81.2% <100%> (+0.82%) ⬆️
superset/db_engine_specs.py 55.7% <0%> (+0.87%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 160e477...548b88c. Read the comment docs.

@john-bodley john-bodley merged commit adfe9e3 into apache:master Oct 5, 2018
@john-bodley john-bodley deleted the john-bodley-fix-tablemodelview-api-read branch October 5, 2018 21:04
john-bodley added a commit to john-bodley/superset that referenced this pull request Oct 8, 2018
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants