From 11977bac686cddf8879a25849f78d745c22cdf69 Mon Sep 17 00:00:00 2001 From: gecong1973 Date: Tue, 27 Nov 2018 18:14:54 -0800 Subject: [PATCH] Add backup search for sql The patch add backup search for sql Change-Id: Id2a0aef2fb3c79684e3ce3e09574f58dcc331fb5 --- freezer_api/db/sqlalchemy/api.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/freezer_api/db/sqlalchemy/api.py b/freezer_api/db/sqlalchemy/api.py index 7507a255..4e0cf20c 100644 --- a/freezer_api/db/sqlalchemy/api.py +++ b/freezer_api/db/sqlalchemy/api.py @@ -576,7 +576,12 @@ def search_action(user_id, project_id=None, offset=0, actionmap['freezer_action']['log_file'] = action.get('log_file') actions.append(actionmap) - actions = filter_tuple_by_search_opt(actions, search) + # If search opt is wrong, filter will not work, + # return all tuples. + try: + actions = filter_tuple_by_search_opt(actions, search) + except Exception as e: + LOG.error(e) return actions @@ -852,7 +857,7 @@ def search_backup(user_id, project_id=None, offset=0, result = search_tuple(tablename=models.Backup, user_id=user_id, project_id=project_id, offset=offset, - limit=limit, search=search) + limit=limit) for backup in result: backupmap = {} backupmap['project_id'] = project_id @@ -863,6 +868,13 @@ def search_backup(user_id, project_id=None, offset=0, json_decode(backup.get('backup_metadata')) backups.append(backupmap) + # If search opt is wrong, filter will not work, + # return all tuples. + try: + backups = filter_tuple_by_search_opt(backups, search) + except Exception as e: + LOG.error(e) + return backups