Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support filter kw on collections.where #74

Open
ingwinlu opened this issue Jul 10, 2023 · 1 comment
Open

Support filter kw on collections.where #74

ingwinlu opened this issue Jul 10, 2023 · 1 comment

Comments

@ingwinlu
Copy link

google-cloud-firestore = "^2.11.1"
mock-firestore = "^0.11.0"

site-packages/google/cloud/firestore_v1/base_collection.py:290: UserWarning: Detected filter using positional arguments. Prefer using the 'filter' keyword argument instead.

i.e. instead of
col.where(_DELETED_ATTR, "==", False)

it is recommended to:

_DELETED_FILTER = FieldFilter(_DELETED_ATTR, "==", False)
col = col.where(filter=_DELETED_FILTER)

current where typesig + docs:

    def where(
        self,
        field_path: Optional[str] = None,
        op_string: Optional[str] = None,
        value=None,
        *,
        filter=None
    ) -> BaseQuery:
        """Create a "where" query with this collection as parent.

        See
        :meth:`~google.cloud.firestore_v1.query.Query.where` for
        more information on this method.

        Args:
            field_path (str): A field path (``.``-delimited list of
                field names) for the field to filter on. Optional.
            op_string (str): A comparison operation in the form of a string.
                Acceptable values are ``<``, ``<=``, ``==``, ``>=``, ``>``,
                and ``in``. Optional.
            value (Any): The value to compare the field against in the filter.
                If ``value`` is :data:`None` or a NaN, then ``==`` is the only
                allowed operation.  If ``op_string`` is ``in``, ``value``
                must be a sequence of values. Optional.
            filter (class:`~google.cloud.firestore_v1.base_query.BaseFilter`): an instance of a Filter.
                Either a FieldFilter or a CompositeFilter.
        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`:
            A filtered query.
        Raises:
            ValueError, if both the positional arguments (field_path, op_string, value)
                and the filter keyword argument are passed at the same time.
        """

Should be fairly simple to extend the mock where call to have same behaviour. Any objections?

thromer added a commit to thromer/python-mock-firestore that referenced this issue Apr 13, 2024
Doesn't support composite filters.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is up to date with 'origin/master'.
#
# Changes to be committed:
#	modified:   mockfirestore/collection.py
#	modified:   mockfirestore/query.py
#	modified:   tests/test_collection_reference.py
#
@thromer
Copy link

thromer commented Apr 13, 2024

I submitted a pull request to support the filter keyword for FieldFilter objects here: #82

raindrift pushed a commit to raindrift/python-mock-firestore that referenced this issue Sep 19, 2024
Doesn't support composite filters.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is up to date with 'origin/master'.
#
# Changes to be committed:
#	modified:   mockfirestore/collection.py
#	modified:   mockfirestore/query.py
#	modified:   tests/test_collection_reference.py
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants