inveniosoftware / invenio

Invenio digital library framework
https://invenio.readthedocs.io
MIT License
625 stars 292 forks source link

NameError: global name 'get_nearest_terms_in_idxphrase_with_collection' is not defined #3271

Closed crepererum closed 9 years ago

crepererum commented 9 years ago

Affected versions

Everything since 4b95199889cbf814a2ef134cb149946f44a58d1e, so maint-2.1 and master.

Error

XXX.YYY.ZZZ.WWW - - [15/Jun/2015 13:28:13] "GET /search?ln=en&p=&action_browse= HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/code/invenio/ext/legacy/__init__.py", line 114, in __call__
    response = self.app.handle_exception(e)
  File "/usr/local/lib/python2.7/site-packages/flask_restful/__init__.py", line 270, in error_router
    return original_handler(e)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/code/invenio/ext/legacy/__init__.py", line 110, in __call__
    response = self.app.full_dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/site-packages/flask_restful/__init__.py", line 270, in error_router
    return original_handler(e)
  File "/code/invenio/base/wrappers.py", line 133, in handle_user_exception
    return super(Flask, self).handle_user_exception(e)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask_debugtoolbar/__init__.py", line 125, in dispatch_request
    return view_func(**req.view_args)
  File "/code/invenio/base/decorators.py", line 203, in decorator
    return f(*args, **argd)
  File "/code/invenio/modules/collections/decorators.py", line 56, in decorated
    return method(collection, *args, **kwargs)
  File "/code/invenio/modules/search/views/search.py", line 344, in search
    return browse()
  File "/code/invenio/base/decorators.py", line 82, in decorated_function
    ctx = f(*args, **kwargs)
  File "/code/invenio/base/decorators.py", line 203, in decorator
    return f(*args, **argd)
  File "/code/invenio/modules/collections/decorators.py", line 56, in decorated
    return method(collection, *args, **kwargs)
  File "/code/invenio/modules/search/views/search.py", line 279, in browse
    colls=colls, p=p, f=f, rg=rg, ln=g.ln))
  File "/code/invenio/legacy/search_engine/__init__.py", line 254, in browse_pattern_phrases
    browsed_phrases_in_colls = get_nearest_terms_in_idxphrase_with_collection(p, index_id, rg/2, rg/2, coll_hitset)
NameError: global name 'get_nearest_terms_in_idxphrase_with_collection' is not defined

Steps to reproduce

Method a:

  1. Go to the landing page /
  2. Click on the +-Party near the search field,
  3. Click on Browse at the bottom right in the option field that appears

Method b:

  1. Go to /search?action_browse=

    Cause

4b95199889cbf814a2ef134cb149946f44a58d1e

jacquerie commented 9 years ago

I did some digging on this. In commit aebbd45, the one before 4b95199, get_nearest_terms_in_idxphrase_with_collection was in the same file as its use: https://github.com/inveniosoftware/invenio/blob/aebbd45f5aae03fd70804192744a4b80d258f9b4/invenio/legacy/search_engine/__init__.py#L3487. So we need to add back the import from its new location in 4b95199.

Then, a parameter name changed from f to index_id everywhere except that in the function declaration.

Finally, when no model is given (which is the case when clicking "browse" as described in the issue), the method should return an empty list and not None, since we will eventually try to map over it: https://github.com/inveniosoftware/invenio/blob/f6bee4828bf93f66bef1885f09c421d1eb083c6f/invenio/modules/search/views/search.py#L276.

I tentatively created https://github.com/jacquerie/invenio/commit/901a04db18d3eee34eea4b8fd842a1fb59f55554 that fixes the present issue. Should I submit a PR?

jirikuncar commented 9 years ago

I tentatively created jacquerie@901a04d that fixes the present issue. Should I submit a PR?

Yes. Please add FIX label to commit messages. Thanks