@@ -526,24 +526,24 @@ class TableModelView(CaravelModelView, DeleteMixin): # noqa
526
526
'changed_by_' , 'changed_on_' ]
527
527
order_columns = [
528
528
'table_link' , 'database' , 'is_featured' , 'changed_on_' ]
529
- add_columns = [
530
- 'table_name' , 'database' , 'schema' ,
531
- 'default_endpoint' , 'offset' , 'cache_timeout' ]
529
+ add_columns = ['table_name' , 'database' , 'schema' ]
532
530
edit_columns = [
533
531
'table_name' , 'sql' , 'is_featured' , 'database' , 'schema' ,
534
532
'description' , 'owner' ,
535
533
'main_dttm_col' , 'default_endpoint' , 'offset' , 'cache_timeout' ]
536
534
related_views = [TableColumnInlineView , SqlMetricInlineView ]
537
535
base_order = ('changed_on' , 'desc' )
538
536
description_columns = {
539
- 'offset' : "Timezone offset (in hours) for this datasource" ,
540
- 'schema' : (
537
+ 'offset' : _ ("Timezone offset (in hours) for this datasource" ),
538
+ 'table_name' : _ (
539
+ "Name of the table that exists in the source database" ),
540
+ 'schema' : _ (
541
541
"Schema, as used only in some databases like Postgres, Redshift "
542
542
"and DB2" ),
543
543
'description' : Markup (
544
544
"Supports <a href='https://daringfireball.net/projects/markdown/'>"
545
545
"markdown</a>" ),
546
- 'sql' : (
546
+ 'sql' : _ (
547
547
"This fields acts a Caravel view, meaning that Caravel will "
548
548
"run a query against this string as a subquery."
549
549
),
@@ -561,17 +561,26 @@ class TableModelView(CaravelModelView, DeleteMixin): # noqa
561
561
'cache_timeout' : _ ("Cache Timeout" ),
562
562
}
563
563
564
- def post_add (self , table ):
565
- table_name = table . table_name
564
+ def pre_add (self , table ):
565
+ # Fail before adding if the table can't be found
566
566
try :
567
- table .fetch_metadata ()
567
+ table .get_sqla_table_object ()
568
568
except Exception as e :
569
569
logging .exception (e )
570
- flash (
571
- "Table [{}] doesn't seem to exist, "
572
- "couldn't fetch metadata" .format (table_name ),
573
- "danger" )
570
+ raise Exception (
571
+ "Table [{}] could not be found, "
572
+ "please double check your "
573
+ "database connection, schema, and "
574
+ "table name" .format (table .table_name ))
575
+
576
+ def post_add (self , table ):
577
+ table .fetch_metadata ()
574
578
utils .merge_perm (sm , 'datasource_access' , table .perm )
579
+ flash (_ (
580
+ "The table was created. As part of this two phase configuration "
581
+ "process, you should now click the edit button by "
582
+ "the new table to configure it." ),
583
+ "info" )
575
584
576
585
def post_update (self , table ):
577
586
self .post_add (table )
0 commit comments