Skip to content

Commit

Permalink
Simplify some SQL datastore code
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 595394399
  • Loading branch information
xingyousong authored and copybara-github committed Jan 3, 2024
1 parent fb523c7 commit 908c293
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions vizier/_src/service/sql_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ def create_trial(self, trial: study_pb2.Trial) -> resources.TrialResource:
try:
self._connection.execute(query)
return trial_resource
except sqla.exc.IntegrityError as integrity_error:
raise custom_errors.AlreadyExistsError(
except sqla.exc.IntegrityError as e:
raise AlreadyExistsError(
'Trial with name %s already exists.' % trial.name
) from integrity_error
) from e

def get_trial(self, trial_name: str) -> study_pb2.Trial:
query = sqla.select(self._trials_table)
Expand Down Expand Up @@ -405,14 +405,10 @@ def list_suggestion_operations(
all_ops = [
operations_pb2.Operation.FromString(row.serialized_op) for row in result
]
if filter_fn is not None:
output_list = []
for op in all_ops:
if filter_fn(op):
output_list.append(op)
return output_list
else:

if filter_fn is None:
return all_ops
return [op for op in all_ops if filter_fn(op)]

def max_suggestion_operation_number(
self, study_name: str, client_id: str
Expand Down

0 comments on commit 908c293

Please sign in to comment.