Test errors with fixtures

19 views
Skip to first unread message

Ralph

unread,
Nov 26, 2009, 7:57:12 AM11/26/09
to django-haystack
Hi there,

I recentyly installed django-haystack with whoosh as backend. The
setup works
fine in a browser interface.

I am having however trouble to run unit tests in django .
I might be missing something here but couldn't find specific
information in the haystack docs.

In tests I use fixtures and I get an error
The model '<mymodel>' does not have a model_attr 'user'.

The 'user' attribute is however part of the fixture Json file and
without
haystack and whoosh the fixtures load without errors.

Then I get lots of follow-up errors
File exists..._MAIN_LOCK

Any suggestions or pointers how I can get the tests to work?
Thanks

Daniel Lindsley

unread,
Nov 30, 2009, 10:04:04 PM11/30/09
to django-...@googlegroups.com
Ralph,


Sorry for the delay. What I think is happening is that the fixture
data may be being loaded out of order (``mymodel`` before ``user``),
resulting in the ``mymodel`` trying to save (and update the index)
before the ``user`` attribute is present. Without seeing the fixture
(or a stripped down example), it's difficult to tell.

You have a couple options. You could disable search for your tests
(in your test settings, set ``HAYSTACK_SEARCH_ENGINE = 'dummy'``), you
could use the regular ``SearchIndex`` instead of
``RealTimeSearchIndex`` (which doesn't automatically try to update the
index on save) or specify ``null=True`` on the field in question. Each
one of these three has their drawbacks (tests no longer perfectly
reflect standard setup/need to manually ``./manage.py update_index``
via cron on the live site/risk imperfect data loaded into the index on
the live setup just so tests work). I suspect option #2 is your best
bet, given that Whoosh will suffer locking issues (the "_MAIN_LOCK"
error) once you start serving traffic.


Daniel
> --
>
> You received this message because you are subscribed to the Google Groups "django-haystack" group.
> To post to this group, send email to django-...@googlegroups.com.
> To unsubscribe from this group, send email to django-haysta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-haystack?hl=en.
>
>
>
Reply all
Reply to author
Forward
0 new messages