diff --git a/src/caoscrawler/identifiable_adapters.py b/src/caoscrawler/identifiable_adapters.py index 0b00cbeaefe42bcf600db735d27c67571ca6a79b..6399bd4937dc3503cacdf55aab869a9c917e6e38 100644 --- a/src/caoscrawler/identifiable_adapters.py +++ b/src/caoscrawler/identifiable_adapters.py @@ -52,8 +52,11 @@ def convert_value(value): return str(value.id) elif isinstance(value, datetime): return value.isoformat() + elif isinstance(value, str): + # replace single quotes, otherwise they may break the queries + return str(value.replace("'", "\'")) else: - return str(value) + return value class IdentifiableAdapter(metaclass=ABCMeta): @@ -387,7 +390,8 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter): if self.check_record(record, identifiable): candidates.append(record) if len(candidates) > 1: - raise RuntimeError("Identifiable was not defined unambigiously.") + raise RuntimeError( + f"Identifiable was not defined unambigiously. Possible candidates are {candidates}") if len(candidates) == 0: return None return candidates[0] @@ -469,7 +473,8 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter): query_string = self.create_query_for_identifiable(identifiable) candidates = db.execute_query(query_string) if len(candidates) > 1: - raise RuntimeError("Identifiable was not defined unambigiously.") + raise RuntimeError( + f"Identifiable was not defined unambigiously.\n{query_string}\nReturned the following {candidates}.") if len(candidates) == 0: return None return candidates[0]