1- from typing import Dict , Any
21from ckan .types import Context , DataDict , Action , ChainedAction
32
43from ckan .plugins import toolkit
54from ckan .lib .navl .dictization_functions import validate
65
76from ckanext .datastore .logic .schema import datastore_search_schema
8- from ckanext .datastore_search .backend import DatastoreSearchBackend
7+ from ckanext .datastore_search .backend import (
8+ DatastoreSearchBackend ,
9+ DatastoreSearchException
10+ )
911
1012
1113ignore_missing = toolkit .get_validator ('ignore_missing' )
1214ignore_not_sysadmin = toolkit .get_validator ('ignore_not_sysadmin' )
1315
1416
15- def datastore_search_create_callback (data_dict ):
17+ def datastore_search_create_callback (data_dict : DataDict ):
1618 backend = DatastoreSearchBackend .get_active_backend ()
1719 backend .create_callback (data_dict )
1820
@@ -24,7 +26,10 @@ def datastore_create(up_func: Action,
2426 data_dict ['include_records' ] = True
2527 func_result = up_func (context , data_dict )
2628 backend = DatastoreSearchBackend .get_active_backend ()
27- backend .create (dict (func_result ))
29+ try :
30+ backend .create (dict (func_result ))
31+ except DatastoreSearchException :
32+ pass
2833 return func_result
2934
3035
@@ -35,7 +40,10 @@ def datastore_upsert(up_func: Action,
3540 data_dict ['include_records' ] = True
3641 func_result = up_func (context , data_dict )
3742 backend = DatastoreSearchBackend .get_active_backend ()
38- backend .upsert (dict (func_result ))
43+ try :
44+ backend .upsert (dict (func_result ))
45+ except DatastoreSearchException :
46+ pass
3947 return func_result
4048
4149
@@ -46,7 +54,10 @@ def datastore_delete(up_func: Action,
4654 data_dict ['include_records' ] = True
4755 func_result = up_func (context , data_dict )
4856 backend = DatastoreSearchBackend .get_active_backend ()
49- backend .delete (dict (func_result ))
57+ try :
58+ backend .delete (dict (func_result ))
59+ except DatastoreSearchException :
60+ pass
5061 return func_result
5162
5263
@@ -64,7 +75,10 @@ def datastore_search(up_func: Action,
6475 ds_meta = up_func (context , {'resource_id' : data_dict .get ('resource_id' ),
6576 'limit' : 0 })
6677 backend = DatastoreSearchBackend .get_active_backend ()
67- records = backend .search (data_dict )
78+ try :
79+ records = backend .search (dict (data_dict ))
80+ except DatastoreSearchException :
81+ return up_func (context , data_dict )
6882 return dict (ds_meta , records = records )
6983
7084
@@ -74,5 +88,8 @@ def datastore_run_triggers(up_func: Action,
7488 data_dict : DataDict ) -> ChainedAction :
7589 func_result = up_func (context , data_dict )
7690 backend = DatastoreSearchBackend .get_active_backend ()
77- backend .reindex (resource_id = data_dict .get ('resource_id' ))
91+ try :
92+ backend .reindex (resource_id = data_dict .get ('resource_id' ))
93+ except DatastoreSearchException :
94+ pass
7895 return func_result
0 commit comments