Closed dmytrokyrychuk closed 10 years ago
Thanks for the report Dmytro, there's still a bug in the exists
query. To
fix this I will have to change the serialization of the hash-based index,
which will break compatibility with earlier versions of the library. I'll
fix this in the coming days.
2014-11-01 16:32 GMT+01:00 Dmytro Kyrychuk notifications@github.com:
Here is a program I used to check $exists query operator behavior:
from blitzdb import FileBackend as Backendfrom blitzdb import Document
class Actor(Document): pass
if name == 'main': backend = Backend('testdb') backend.filter(Actor, {}).delete() backend.commit()
marlon_brando = Actor({'name': 'Marlon Brando'}) leonardo_di_caprio = Actor({'name': 'Leonardo di Caprio', 'gross_income_m': 12.453}) david_hasselhoff = Actor({'name': 'David Hasselhoff', 'gross_income_m': 12.453}) charlie_chaplin = Actor({'name': 'Charlie Chaplin', 'gross_income_m': 0.371}) backend.save(marlon_brando) backend.save(leonardo_di_caprio) backend.save(david_hasselhoff) backend.save(charlie_chaplin) backend.commit() print([a.name for a in backend.filter(Actor, {'gross_income_m': {'$exists': True}})]) print([a.name for a in backend.filter(Actor, {'gross_income_m': {'$exists': False}})])
This must print something like this:
['Charlie Chaplin', 'Leonardo di Caprio', 'David Hasselhoff'] ['Marlon Brando']
Actually tis script prints this:
['Charlie Chaplin', 'Leonardo di Caprio', 'David Hasselhoff'] ['Charlie Chaplin', 'Leonardo di Caprio', 'David Hasselhoff']
Please stop catching errors like this https://github.com/adewes/blitzdb/blob/master/blitzdb/tests/test_query_operators.py#L317-L321, this https://github.com/adewes/blitzdb/blob/master/blitzdb/tests/test_query_operators.py#L325-L329, this https://github.com/adewes/blitzdb/blob/master/blitzdb/tests/test_query_operators.py#L338-L342, this https://github.com/adewes/blitzdb/blob/master/blitzdb/tests/test_query_operators.py#L346-L350, this https://github.com/adewes/blitzdb/blob/master/blitzdb/tests/test_query_operators.py#L354-L358 and many others. Tests must fail when something works wrong. That is the way tests notify developers that something bad happened.
— Reply to this email directly or view it on GitHub https://github.com/adewes/blitzdb/issues/33.
OK it should work now. I fixed the tests for the operator as well, please review if you like @orgkhnargh. I think we'll have to start thinking about versioning for the file backend.
Here is a program I used to check $exists query operator behavior:
This must print something like this:
Actually tis script prints this:
Please stop catching errors like this, this, this, this, this and many others. Tests must fail when something works wrong. That is the way tests notify developers that something bad happened.