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

Simple fix for thrown exception when SearchManager search_field is None #72

Open
hfickes opened this issue Jan 28, 2016 · 0 comments
Open

Comments

@hfickes
Copy link

hfickes commented Jan 28, 2016

If your model has:
objects = SearchManager(fields=None, search_field=None)

so you can do searches with

table.objects.search('text to search', fields=('field1', 'field2'))

then the djorm_pgfulltext/models.py will throw an exception from within SearchQuerySet's search() method at line 285:

            full_search_field = "%s.%s" % (
                qn(self.model._meta.db_table),
                qn(self.manager.search_field)
            )

because self.manager.search_field is None so qn throws the exception.

The fix for this is simple, move that block of code down a few lines to be where it is actually used:

        # if fields is passed, obtain a vector expression with
        # these fields. In other case, intent use of search_field if
        # exists.
        if fields:
            search_vector = self.manager._get_search_vector(config, using, fields=fields)
        else:
            **full_search_field **= "%s.%s" % (
                qn(self.model._meta.db_table),
                qn(self.manager.search_field)
            )
            if not self.manager.search_field:
                raise ValueError("search_field is not specified")

            search_vector = **full_search_field**

We will probably fork the code locally for this fix, but will undo our fork once its fixed in this or some other fashion.

Thank you for writing this package, we really appreciate it,
-herb

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