Skip to content

Commit 76c8d32

Browse files
committed
Use savepoints to recover from potentially failed transactions if input_value validation fails
1 parent 5fc1a34 commit 76c8d32

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/dataset_features_provider.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,13 +925,16 @@ def validate_fields(self, feature):
925925

926926
# validate data type
927927

928+
conn.execute(sql_text("SAVEPOINT before_validation"))
928929
try:
929930
# try to parse value on DB
930931
sql = sql_text("SELECT (:value):: %s AS value;" % data_type)
931932
result = conn.execute(sql, {"value": input_value}).mappings()
932933
for row in result:
933934
value = row['value']
935+
conn.execute(sql_text("RELEASE SAVEPOINT before_validation"))
934936
except (DataError, ProgrammingError) as e:
937+
conn.execute(sql_text("ROLLBACK TO SAVEPOINT before_validation"))
935938
# NOTE: current transaction is aborted
936939
errors.append(self.translator.tr("validation.invalid_value") %
937940
(attr, data_type))

0 commit comments

Comments
 (0)