mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 03:38:53 -05:00
[Mongo] Use escaped identifiers to extract inner value (#2832)
This was causing a KeyError to be raised whenever a key containing $ or . was part of the identifiers path, even if the value was actually in the dict. Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
parent
03e59ea9d3
commit
f2039300c2
@ -119,9 +119,9 @@ class Mongo(BaseDriver):
|
|||||||
mongo_collection = self.get_collection(identifier_data.category)
|
mongo_collection = self.get_collection(identifier_data.category)
|
||||||
|
|
||||||
pkey_filter = self.generate_primary_key_filter(identifier_data)
|
pkey_filter = self.generate_primary_key_filter(identifier_data)
|
||||||
|
escaped_identifiers = list(map(self._escape_key, identifier_data.identifiers))
|
||||||
if len(identifier_data.identifiers) > 0:
|
if len(identifier_data.identifiers) > 0:
|
||||||
dot_identifiers = ".".join(map(self._escape_key, identifier_data.identifiers))
|
proj = {"_id": False, ".".join(escaped_identifiers): True}
|
||||||
proj = {"_id": False, dot_identifiers: True}
|
|
||||||
|
|
||||||
partial = await mongo_collection.find_one(filter=pkey_filter, projection=proj)
|
partial = await mongo_collection.find_one(filter=pkey_filter, projection=proj)
|
||||||
else:
|
else:
|
||||||
@ -132,7 +132,7 @@ class Mongo(BaseDriver):
|
|||||||
if partial is None:
|
if partial is None:
|
||||||
raise KeyError("No matching document was found and Config expects a KeyError.")
|
raise KeyError("No matching document was found and Config expects a KeyError.")
|
||||||
|
|
||||||
for i in identifier_data.identifiers:
|
for i in escaped_identifiers:
|
||||||
partial = partial[i]
|
partial = partial[i]
|
||||||
if isinstance(partial, dict):
|
if isinstance(partial, dict):
|
||||||
return self._unescape_dict_keys(partial)
|
return self._unescape_dict_keys(partial)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user