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

Implement `.exclude` #62

Open
wants to merge 5 commits into
base: master
from
Open

Conversation

@EmilioCarrion
Copy link

@EmilioCarrion EmilioCarrion commented Feb 26, 2020

Implemented the .exclude() method in the queryset.
Implemented as a parametrization of the filter method where if we are excluding we invert the sql compose clause

@@ -94,14 +94,16 @@ def build_select_expression(self):

return expr

def filter(self, **kwargs):
def filter(self, exclude=False, **kwargs):

This comment has been minimized.

@tomchristie

tomchristie Feb 26, 2020
Member

I wonder if we should use _exclude, to make it private-ish, and help ensure it shouldn't clash with any of the provided kwargs?

This comment has been minimized.

@EmilioCarrion

EmilioCarrion Feb 26, 2020
Author

Totally true, I isolated the parsing logic in a private method avoiding any posible clash with field names

def exclude(self, **kwargs):
return self._parse_filters(exclude=True, **kwargs)

def _parse_filters(self, exclude=False, **kwargs):

This comment has been minimized.

@rzane

rzane Feb 26, 2020
Contributor

@EmilioCarrion, even with your latest changes, exclude could conflict one of the parameters used for filtering. Take a look at the following example:

class Person(orm.Model):
    id = orm.Integer(primary_key=True)
    exclude = orm.String(max_length=100)

await Person.filter(exclude=True).all()

The column name exclude conflicts with the exclude parameter in _parse_filters.

One solution would be to change the definition of _parse_filters to the following:

def _parse_filters(self, values, exclude=False):

Alternatively, you could rename exclude to _exclude.

@EmilioCarrion EmilioCarrion requested a review from tomchristie Feb 29, 2020
orm/models.py Outdated Show resolved Hide resolved
EmilioCarrion and others added 2 commits May 21, 2020
Co-authored-by: Rafał Pitoń <kontakt@rpiton.com>
@EmilioCarrion EmilioCarrion requested a review from rafalp May 22, 2020
@rafalp rafalp requested a review from encode/maintainers May 22, 2020
clauses.append(clause)

if exclude:
filter_clauses.append(~sqlalchemy.sql.and_(*clauses))

This comment has been minimized.

@rafalp

rafalp May 24, 2020
Member

Can we replace unary operator with not_? It will be more obvious that way.

@rafalp rafalp mentioned this pull request Jun 17, 2020
@rafalp rafalp self-requested a review Aug 5, 2020
@rafalp
rafalp approved these changes Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.