MongoEngine/mongoengine

SECONDARY_PREFERRED returns None for `test_read_preference` test

njgrisafi opened this issue · 2 comments

Trying to run the test test_read_preference on version 0.14 and running into the follow error:

======================================================================
FAIL: test_read_preference (tests.queryset.queryset.QuerySetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/mongoengine/build/lib/tests/queryset/queryset.py", line 4323, in test_read_preference
    ReadPreference.SECONDARY_PREFERRED)
AssertionError: None != SecondaryPreferred(tag_sets=None, max_staleness=-1, hedge=None)
    'None != SecondaryPreferred(tag_sets=None, max_staleness=-1, hedge=None)' = '%s != %s' % _common_shorten_repr(None, second)
    'None != SecondaryPreferred(tag_sets=None, max_staleness=-1, hedge=None)' = self._formatMessage('None != SecondaryPreferred(tag_sets=None, max_staleness=-1, hedge=None)', 'None != SecondaryPreferred(tag_sets=None, max_staleness=-1, hedge=None)')
>>  raise self.failureException('None != SecondaryPreferred(tag_sets=None, max_staleness=-1, hedge=None)')

The running mongo server version is 3.0.14 and PyMongo 3.12.3. Passing in ReadPreference.SECONDARY or ReadPreference.PRIMARY works fine but not ReadPreference.SECONDARY_PREFERRED.

The test doesn't seem to have changed much on the latest master so I'm curious if I'm missing something in my local setup to run this test.

Was testing this a bit more today using pdb and the cursor read preference is returning None:

(Pdb) bars._cursor._Cursor__read_preference == None
True

Confirmed by commenting out all the asserts on _cursor checks it passes.

downgrading pymongo to 3.2.2 fixed the issue.