toconnell / kdm-manager

An interactive campaign manager for the game "Monster", by Kingdom Death. Development blog and release notes at https://blog.kdm-manager.com This project has no affiliation with Kingdom Death and is a totally independent, fan-maintained project.
http://kdm-manager.com
Other
26 stars 11 forks source link

API: weird error from set_latest_action() call #494

Closed toconnell closed 6 years ago

toconnell commented 6 years ago

User OID: 666 Method: GET URL: http://localhost/ JSON: None

Traceback (most recent call last):
File "/home/toconnell/kdm-manager/v2/api/utils.py", line 539, in wrapper
 return log_event_call(self, *args, **kwargs)
File "/home/toconnell/kdm-manager/v2/api/Models.py", line 973, in log_event
 request.User.set_latest_action(d['event'], ua_string)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/local.py", line 343, in __getattr__
 return getattr(self._get_current_object(), name)
AttributeError: 'Request' object has no attribute 'User'
toconnell commented 6 years ago

It's obviously an un-handled condition that comes up when trying to record some kind of event...

toconnell commented 6 years ago

This doesn't address root cause, but we're going to try it for now, just to squelch the emails:

diff --git a/v2/api/Models.py b/v2/api/Models.py
index f5dc306..0bb7b26 100644
--- a/v2/api/Models.py
+++ b/v2/api/Models.py
@@ -989,7 +989,7 @@ class UserAsset(object):
         # finally, if we had a requester, now that we've settled on a message
         # text, update the requester's latest action with it
         if 'created_by' is not None:
-            if request:
+            if request and hasattr(request, 'User'):
                 ua_string = str(ua_parse(request.user_agent.string))
                 request.User.set_latest_action(d['event'], ua_string)