Skip to content

Conversation

@CeeEffEff
Copy link
Contributor

@CeeEffEff CeeEffEff commented Jan 24, 2025

In our tools we are requiring more complex queries than single FieldFilters, or a group joined in a kind of "And" behaviour.
Because Firestore supports more complex queries than this, and we are using them, this PR updates mockfirestore so that we can effortlessly use these nice features without having to craft convoluted tests.

Of note is that I am supporting the native Firestore objects, not creating any new kinds of query objects.

I've added a test to show the kind of usage now supported.

@CeeEffEff CeeEffEff marked this pull request as ready for review January 24, 2025 14:51
Copy link
Contributor

@marian-stykhun marian-stykhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Few minor changes

op: Optional[str] = None,
value: Optional[Any] = None,
filter: Optional[FieldFilter] = None,
filter: Union[FieldFilter, And, Or, None] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not critical
May we use OptionalUnion[FieldFilter, And, Or] ?
As None is not a type. and using Union[type, None] is outdated

Copy link
Contributor Author

@CeeEffEff CeeEffEff Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional is just shorthand for Union[x, None].
In this case it wouldn't make things much shorter as you end up with Optional[Union[x]].
It's not deprecated either to use Union

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't
Thats why it isnt critical.
But even python's creators decided that it is bad design :)

if filter is not None:
field, op, value = filter.field_path, filter.op_string, filter.value
if field is None or op is None or value is None:
if filter is None and (field is None or op is None or value is None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter is None and not any([field, op, value])?
Or we need i direct check is None ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes as we cannot rely on the truthiness of value.
We are explicitly checking for if the params have not been provided.

@CeeEffEff CeeEffEff merged commit d26e457 into main Jan 24, 2025
10 checks passed
@CeeEffEff CeeEffEff deleted the feat/add-query-support branch January 24, 2025 17:11
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

Successfully merging this pull request may close these issues.

2 participants