diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fe71126..fd27768 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: autoflake args: ["--remove-all-unused-imports", "--remove-unused-variables", "--ignore-init-module-imports", "-i"] - repo: https://github.com/psf/black - rev: 21.9b0 + rev: 22.3.0 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 diff --git a/atlasq/queryset/queryset.py b/atlasq/queryset/queryset.py index cd51b1e..9d8a7b2 100644 --- a/atlasq/queryset/queryset.py +++ b/atlasq/queryset/queryset.py @@ -88,19 +88,44 @@ def _cursor(self): return cursor def order_by(self, *keys): - other = self.clone() - order_by: List[Tuple[str, int]] = other._get_order_by(keys) - aggregation = {"$sort": {key: value for key, value in order_by}} - other._other_aggregations.append(aggregation) - return other + if not keys: + return self + qs: AtlasQuerySet = self.clone() + order_by: List[ + Tuple[str, int] + ] = qs._get_order_by( # pylint: disable=protected-access + keys + ) + aggregation = {"$sort": dict(order_by)} + qs._other_aggregations.append(aggregation) # pylint: disable=protected-access + return qs + + def __getitem__(self, key): + if isinstance(key, int): + from mongoengine.queryset.base import BaseQuerySet + + qs = self.clone() + qs._limit = 1 + return BaseQuerySet.__getitem__(qs, key) + return super().__getitem__(key) @property def _query(self): if not self._search_result: return None + start = self._skip + end = self._limit # unfortunately here we have to actually run the query to get the objects - # i do not see other way to do this atm - self._query_obj = Q(id__in=[obj["_id"] for obj in self._search_result if obj]) + # I do not see other way to do this atm + ids: List[str] = [] + for i, obj in enumerate(self._search_result): + if end is not None and i >= end: + break + if start is not None and i < start: + continue + if obj: + ids.append(obj["_id"]) + self._query_obj = Q(id__in=ids) logger.debug(self._query_obj.to_query(self._document)) return super()._query diff --git a/atlasq/queryset/transform.py b/atlasq/queryset/transform.py index c0377bd..efdba37 100644 --- a/atlasq/queryset/transform.py +++ b/atlasq/queryset/transform.py @@ -217,7 +217,7 @@ def transform( if atlas_index.ensured: # if we are using the embedded object, in the index is defined only the first level if atlas_index.use_embedded_documents: - path = path.split(".")[0] + path = path.split(".", maxsplit=1)[0] self._ensure_keyword_is_indexed(atlas_index, path) logger.debug(obj) diff --git a/setup.py b/setup.py index c5ec2b0..1139933 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,3 @@ -""" -# PyDragonfly -Robust Python SDK and CLI for interacting with Certego's Dragonfly service's API. -## Docs & Example Usage: https://github.com/certego/pydragonfly -""" - from pathlib import Path from setuptools import find_packages, setup diff --git a/version.py b/version.py index 93194ea..4283d70 100644 --- a/version.py +++ b/version.py @@ -1 +1 @@ -VERSION = "0.3.4" +VERSION = "0.3.5"