8000 filter_not rewrites previous filters · Issue #111 · heynemann/motorengine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
filter_not rewrites previous filters #111
Open
@ilex

Description

@ilex

It seems that in code as follow:

User.objects.filter(name="test").filter_not(email='test@gmail.com').find_all()

the first filter is ignored.
I think it's because method filter_not just sets self._fitlers and does not do something like self._filters = self._fitlers & QNot(not_filter)

Also the test data to test such case is not good. Actually in file tests/test_document.py test method test_can_find_with_multiple_filters:

def test_can_find_with_multiple_filters(self):
        User.objects.create(email="heynemann@gmail.com", first_name="Bernardo", last_name="Heynemann", callback=self.stop)
        user = self.wait()

        User.objects.create(email="someone@gmail.com", first_name="Someone", last_name="Else", callback=self.stop)
        self.wait()

        User.objects.create(email="someone@gmail.com", first_name="Bernardo", last_name="Heynemann", callback=self.stop)
        self.wait()

        User.objects.create(email="other@gmail.com", first_name="Bernardo", last_name="Silva", callback=self.stop)
        last_user = self.wait()

        User.objects.filter(first_name="Bernardo").filter_not(email="someone@gmail.com").find_all(callback=self.stop)
        users = self.wait()

        expect(users).to_be_instance_of(list)
        expect(users).to_length(2)

        first_user = users[0]
        expect(first_user.first_name).to_equal(user.first_name)
        expect(first_user.last_name).to_equal(user.last_name)
        expect(first_user.email).to_equal(user.email)

        User.objects.filter(last_name="Silva").filter(first_name="Bernardo").find_all(callback=self.stop)
        users = self.wait()

        expect(users).to_be_instance_of(list)
        expect(users).to_length(1)
        expect(users[0]._id).to_equal(last_user._id)

if we change this:

User.objects.filter(first_name="Bernardo").filter_not(email="someone@gmail.com").find_all(callback=self.stop)

to this:

User.objects.filter_not(email="someone@gmail.com").find_all(callback=self.stop)

test will pass anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0