From bd1af369acb99d52ede1b3cade311b8c0a7781d6 Mon Sep 17 00:00:00 2001 From: Luka Peschke Date: Wed, 6 Dec 2023 16:12:05 +0100 Subject: [PATCH] fix: Add garbage code to mongo connector Signed-off-by: Luka Peschke --- toucan_connectors/mongo/mongo_connector.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/toucan_connectors/mongo/mongo_connector.py b/toucan_connectors/mongo/mongo_connector.py index 9f6d955bd..c56529e93 100644 --- a/toucan_connectors/mongo/mongo_connector.py +++ b/toucan_connectors/mongo/mongo_connector.py @@ -5,7 +5,7 @@ import pymongo from bson.son import SON from cached_property import cached_property -from pydantic import ConfigDict, Field, create_model, model_validator +from pydantic import ConfigDict, Field, create_model, field_validator, model_validator from toucan_connectors.common import ConnectorStatus, nosql_apply_parameters_to_query from toucan_connectors.json_wrapper import JsonWrapper @@ -116,8 +116,15 @@ class MongoDataSource(ToucanDataSource): 'Aggregation Pipeline in the MongoDB documentation', ) + # FIXME: This is needed for now because with we rely on empty queries being dicts. In pydantic + # v1, "[]" was coerced to {} + @field_validator("query") @classmethod - def get_form(cls, connector: 'MongoConnector', current_config): + def _ensure_empty_query_is_dict(cls, query: dict | list) -> dict | list: + return query or {} + + @classmethod + def get_form(cls, connector: "MongoConnector", current_config): """ Method to retrieve the form with a current config For example, once the connector is set,