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

FileBackend.filter() does not support the sort_by arguement #25

Open
dalethestirling opened this issue Sep 25, 2014 · 1 comment
Open

Comments

@dalethestirling
Copy link
Contributor

I have been using this feature for a project and have noticed that when I build the query

db.filter(data, {}, sort_by='seq')

It would return a QuerySet object in the same order as if i used the query

db.filter(data, {})

This is true even when i intentionally saved the records to the Document class in a non sequential order.

I tested using this code:

from blitzdb import FileBackend, Document

db = FileBackend('this.db')

class data(Document):
  pass


db.begin()
a = data({'seq': 3})
b = data({'seq': 5})
c = data({'seq': 1})
d = data({'seq': 4})
e = data({'seq': 2})

db.save(a)
db.save(b)
db.save(c)
db.save(d)
db.save(e)

db.commit()

# Filter 1
db.filter(data, {})[0]['seq']
# v0.2.4 return: 3
# fix return: 3

# Filter 2
db.filter(data, {}).sort('seq')[0]['seq']
# v0.2.4 return: 1
# fix return: 1

# Filter 3
from blitzdb.queryset import QuerySet as BaseQS
db.filter(data, {}).sort('seq', BaseQS.DESCENDING)[0]['seq']
# v0.2.4 return: 5
# fix return: 5

# Filter 4
db.filter(data, {}, sort_by='seq')[0]['seq']
# v0.2.4 return: 3 
# fix return: 1

I have built a fix for this and will add the pull request. I have also added tests to test_sorting.py

@dalethestirling
Copy link
Contributor Author

Fix in pull request #26

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

1 participant