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,