Project

General

Profile

Actions

Feature #1269

closed

API: get_by_menu_item() for actors

Added by Bernhard Koschiček-Krombholz almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Category:
API
Target version:
Start date:
2020-06-06
Estimated time:

Description

I try to access the API with json payload. It works fine, but when I'm using the get_by_menu_item function with actor as argument the application crashes with following Stacktrace:

Traceback (most recent call last):
  File "C:\Users\bkoschicek\Desktop\tnt\python\venv\lib\site-packages\flask\app.py", line 2463, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\bkoschicek\Desktop\tnt\python\venv\lib\site-packages\flask\app.py", line 2449, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\bkoschicek\Desktop\tnt\python\venv\lib\site-packages\flask\app.py", line 1866, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\bkoschicek\Desktop\tnt\python\venv\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "C:\Users\bkoschicek\Desktop\tnt\python\venv\lib\site-packages\flask\app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\bkoschicek\Desktop\tnt\python\venv\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\bkoschicek\Desktop\tnt\python\venv\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\bkoschicek\Desktop\tnt\python\venv\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "C:\Users\bkoschicek\Desktop\tnt\python\venv\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\bkoschicek\Desktop\tnt\python\venv\lib\site-packages\flask\app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\bkoschicek\Desktop\OpenAtlas\oa-dev\openatlas\util\util.py", line 370, in wrapped
    return f(*args, **kwargs)
  File "C:\Users\bkoschicek\Desktop\OpenAtlas\oa-dev\openatlas\views\api.py", line 42, in api_get_entities_by_json
    return jsonify(Api.get_entities_by_menu_item(code_=item))
  File "C:\Users\bkoschicek\Desktop\OpenAtlas\oa-dev\openatlas\models\api.py", line 74, in get_entities_by_menu_item
    for entity in Entity.get_by_menu_item(code_):
  File "C:\Users\bkoschicek\Desktop\OpenAtlas\oa-dev\openatlas\models\entity.py", line 390, in get_by_menu_item
    aliases = True if menu_item == 'actor' and current_user.settings[
  File "C:\Users\bkoschicek\Desktop\tnt\python\venv\lib\site-packages\werkzeug\local.py", line 348, in __getattr__
    return getattr(self._get_current_object(), name)
AttributeError: 'AnonymousUserMixin' object has no attribute 'settings'

The API is set to public and I'm not logged in

Actions #1

Updated by Alexander Watzinger almost 4 years ago

  • Subject changed from get_by_menu_item with actor not working in postman to API: get_by_menu_item() with actor not working
  • Category set to API
  • Status changed from New to In Progress
  • Assignee set to Bernhard Koschiček-Krombholz
  • Target version set to 5.3.0
  • Found in version set to 5.2.0

Thank you for the detailed description. Problem was that this function is also used for table views and when trying to access user profile settings to show aliases it failed because a not logged in user has no settings.

Fixed it for now in develop (not logged in user gets no aliases) but depending on how you want to use the functions (e.g. with aliases or a parameter to toggle) we may have to make (not trivial) changes there. So assigned this issue back to you for further processing.

I also commented out some tests in test_api.py because they are failing (at least on my machine). Since we all merge into develop tests there should always pass and ideally have a 100% code coverage. Correct way to do this is to first merge develop to the feature branch, run tests and only if they pass merge the feature branch to develop. I'm aware that this could get tricky with API development on different operating systems but please take a look at it.

Actions #2

Updated by Bernhard Koschiček-Krombholz almost 4 years ago

  • Status changed from In Progress to Closed

Thank you for the fix. It works now.
I don't think, that I need more changes. But I have to test it further with token based authentication.

To the tests, yes this was my bad. I refactored the function names and didn't know that the IDE could not refactor the names in the test. Sorry, next time I will be more careful, it was just in the heat of the moment ;) I will try to concentrate more on tests soon.

Actions #3

Updated by Alexander Watzinger almost 4 years ago

Glad that it works. No worries about the merging stuff that already happened. We all are learning to adapt the workflow as our team grows so I updated the Git workflow page with a more detailed workflow instruction as well.

Also I'm not sure about calling this issue a bug and think it's more about adding functionality. So maybe calling it "API: adapt get_by_menu_item() for actors" and changing it to a feature but it's your ticket and I leave it up to you.

Actions #4

Updated by Bernhard Koschiček-Krombholz almost 4 years ago

  • Tracker changed from Bug to Feature
  • Subject changed from API: get_by_menu_item() with actor not working to API: get_by_menu_item() for actors
  • Found in version deleted (5.2.0)
Actions

Also available in: Atom PDF