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

Fix: Allow the usage of frozenset in the isin(...) and notin(...) functions #744

Merged
merged 2 commits into from
Sep 26, 2023
Merged

Fix: Allow the usage of frozenset in the isin(...) and notin(...) functions #744

merged 2 commits into from
Sep 26, 2023

Conversation

antoninkriz
Copy link
Contributor

This merge request should allow users to use .isin(...) and .notin(...) functions with frozenset as an argument.

Current behavior throws an error as in this minimal reproducible example:

>>> from pypika import Table, Query
>>> best_customers = frozenset([1, 2, 3])
>>> customers = Table('customers')
>>> Query.from_(customers).select(customers.id, customers.name).where(customers.id.isin(best_customers))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/REDACTED_PATH_TO_PYTHON/python3.11/site-packages/pypika/utils.py", line 50, in _copy
    result = func(self_copy, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/REDACTED_PATH_TO_PYTHON/python3.11/site-packages/pypika/queries.py", line 930, in where
    if not self._validate_table(criterion):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/REDACTED_PATH_TO_PYTHON/python3.11/site-packages/pypika/queries.py", line 1155, in _validate_table
    for field in term.fields_():
                 ^^^^^^^^^^^^^^
  File "/REDACTED_PATH_TO_PYTHON/python3.11/site-packages/pypika/terms.py", line 57, in fields_
    return set(self.find_(Field))
               ^^^^^^^^^^^^^^^^^
  File "/REDACTED_PATH_TO_PYTHON/python3.11/site-packages/pypika/terms.py", line 37, in find_
    return [node for node in self.nodes_() if isinstance(node, type)]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/REDACTED_PATH_TO_PYTHON/python3.11/site-packages/pypika/terms.py", line 37, in <listcomp>
    return [node for node in self.nodes_() if isinstance(node, type)]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/REDACTED_PATH_TO_PYTHON/python3.11/site-packages/pypika/terms.py", line 795, in nodes_
    yield from self.container.nodes_()
               ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'frozenset' object has no attribute 'nodes_'
>>> 

@AzisK
Copy link

AzisK commented Sep 7, 2023

Could you add a test for this feature?

@antoninkriz
Copy link
Contributor Author

@AzisK done, tests added ✔️

@AzisK
Copy link

AzisK commented Sep 26, 2023

Looks good. I am merging this but the version will be bumped later. Thanks for your effort

@AzisK AzisK merged commit 351981a into kayak:master Sep 26, 2023
5 checks passed
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