adaptive-learning / proso-apps

Django modules for an adaptive practice system (currently used by http://slepemapy.cz/ or https://anatom.cz/)
MIT License
2 stars 7 forks source link

KeyError on /models/to_practice/ #156

Closed papousek closed 8 years ago

papousek commented 8 years ago

From outlinemaps.org:

[2016-05-31 21:48:37,097] ERROR "Internal Server Error: /models/to_practice/"
Traceback (most recent call last):
  File "/usr/local/share/.virtualenvs/outlinemaps-production-2/lib/python3.5/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/share/.virtualenvs/outlinemaps-production-2/lib/python3.5/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/share/.virtualenvs/outlinemaps-production-2/lib/python3.5/site-packages/proso/django/cache.py", line 25, in __cache_page_conditional
    return f(request, *args, **kwargs)
  File "/usr/local/share/.virtualenvs/outlinemaps-production-2/lib/python3.5/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/share/.virtualenvs/outlinemaps-production-2/lib/python3.5/site-packages/proso_models/views.py", line 53, in to_practice
    return render_json(request, result, template='models_json.html', help_text=to_practice.__doc__)
  File "/usr/local/share/.virtualenvs/outlinemaps-production-2/lib/python3.5/site-packages/proso/django/response.py", line 51, in render_json
    json = enrich_json_objects_by_object_type(request, json)
  File "/usr/local/share/.virtualenvs/outlinemaps-production-2/lib/python3.5/site-packages/proso/django/enrichment.py", line 101, in enrich_json_objects_by_object_type
    enricher_info['enricher'](request, enricher_objects, enricher_nested)
  File "/usr/local/share/.virtualenvs/outlinemaps-production-2/lib/python3.5/site-packages/proso/django/enrichment.py", line 118, in enricher_fun
    return _enricher_fun(enricher)(request, json_list, nested)
  File "/usr/local/share/.virtualenvs/outlinemaps-production-2/lib/python3.5/site-packages/proso_models/json_enrich.py", line 16, in item2object
    for key, value in translated[object_json['id']].items():
KeyError: 5383
papousek commented 8 years ago

The problem here is that the given item is not available for the given language.

pgdb=> select * from proso_flashcards_flashcard where item_id = 5483;
  id   |      identifier      | item_id | context_id | description | lang | term_id | active 
-------+----------------------+---------+------------+-------------+------+---------+--------
  9341 | namerica-Yellowstone |    5483 |        125 | Yellowstone | cs   |   12251 | t
  9506 | namerica-Yellowstone |    5483 |        124 | Yellowstone | en   |   12397 | t
 11501 | namerica-Yellowstone |    5483 |        218 | Yellowstone | sk   |   14090 | t

I will investigate whether there is an error during loading flashcards.

papousek commented 8 years ago

OK. The load_flashcards command seems to be OK. The geography-flashcards.json file contains:

    {
       "categories": [
         "namerica",
         "river"
       ],
       "id": "Yellowstone",
       "name-cs": "Yellowstone",
       "name-en": "Yellowstone",
       "name-sk": "Yellowstone"
     },

I think we already discussed this issue before migration, but I am not sure about the conclusion.

@slaweet @thran: Should the resource /models/to_practice_counts/ return 0 for filter [["context/namerica", "category/river"]] and language es (now it returns 22).

papousek commented 8 years ago

Fixed by d60b3023ed3ee649baf1c3cb746570bee6884044