OpenTechStrategies / torque

A flexible web-based open source system for collaboratively evaluating proposals.
1 stars 2 forks source link

Group is not always properly parsed #56

Closed slifty closed 2 years ago

slifty commented 3 years ago

There is a recurring 500 error in the logs (since at least May 15th) which looks something like:

Internal Server Error: /api/RacialEquity2030/id/809.mwiki
Traceback (most recent call last):
  File "/home/deploy/.local/share/virtualenvs/torquedata-GV3iMLbu/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/deploy/.local/share/virtualenvs/torquedata-GV3iMLbu/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/deploy/torquedata/torque/torquedata/core/views.py", line 259, in get_row_view
    return get_row(group, wiki_key, key, fmt, sheet_name, request.GET.get("view", None))
  File "/home/deploy/torquedata/torque/torquedata/core/views.py", line 229, in get_row
    group=group,
  File "/home/deploy/.local/share/virtualenvs/torquedata-GV3iMLbu/lib/python3.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/deploy/.local/share/virtualenvs/torquedata-GV3iMLbu/lib/python3.7/site-packages/django/db/models/query.py", line 437, in get
    self.model._meta.object_name
core.models.SheetConfig.DoesNotExist: SheetConfig matching query does not exist
[08/Jul/2021 00:09:47] "GET /api/RacialEquity2030/id/809.mwiki?group=&wiki_key=RacialEquity2030&view=Evaluations HTTP/1.0" 500 69666

You'll notice that there is no group defined in the request URL; we need to figure out why and correct the issue.

slifty commented 3 years ago

It seems that the group is populated here

I'm not completely sure why this isn't working yet, but it is worth noting that this code is ultimately is using an outdated way of accessing user ($wgUser) <-- this has been deprecated, and has a warning that it shouldn't be used in new code.

That page also explains that wgUser is populated pretty late in the initialization process, and if a hook is called before it is populated, the user won't always have valid information. Again, I'm not sure if this is the actual issue BUT it could potentially explain the unpredictable nature of this bug -- where sometimes group is populated properly and other times it is not, even for the same user.

One initial thing I want to try is instead using $parser->getUser() instead of $wgUser.

Worst case it fixes nothing, but at least it isn't using that particular deprecated aspect.

slifty commented 3 years ago

Another item is that later in the code we use $user->getGroups() which is deprecated as of 1.35

Apparently we are supposed to instead use UserGroupManager::getUserGroups().

slifty commented 2 years ago

I'm going to close this as stale -- I do think a warning sometimes shows up in logs but it isn't related to functionality at this point. We can re-open / make a new issue if we want to take that one later.