Skip to content

Commit

Permalink
Extend alias checks to length aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Mar 28, 2020
1 parent a1847fc commit 8d176a8
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions optimade/server/entry_collections/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,8 @@ def __init__(
) # The MongoTransformer only supports v0.10.1 as the latest grammar

# check aliases do not clash with mongo operators
self._mapper_aliases = self.resource_mapper.all_aliases()
if any(
alias[0].startswith("$") or alias[1].startswith("$")
for alias in self._mapper_aliases
):
raise RuntimeError(
f"Cannot define an alias starting with a '$': {self._mapper_aliases}"
)
self._check_aliases(self.resource_mapper.all_aliases())
self._check_aliases(self.resource_mapper.all_length_aliases())

def __len__(self):
return self.collection.estimated_document_count()
Expand Down Expand Up @@ -166,3 +160,10 @@ def _parse_params(
cursor_kwargs["skip"] = params.page_offset

return cursor_kwargs

def _check_aliases(self, aliases):
""" Check that aliases do not clash with mongo keywords. """
if any(
alias[0].startswith("$") or alias[1].startswith("$") for alias in aliases
):
raise RuntimeError(f"Cannot define an alias starting with a '$': {aliases}")

0 comments on commit 8d176a8

Please sign in to comment.