theLaborInVain / kdm-manager-api

The API used by https://kdm-manager.com and related Kingdom Death: Monster utilities.
Other
3 stars 0 forks source link

add_defeated_monster() uses old monster object attribute (and fails) #77

Closed toconnell closed 10 months ago

toconnell commented 10 months ago

User OID: 5a42c7f98740d91e070933be Method: POST URL: http://api.kdm-manager.com/settlement/return_survivors/658c87494bd2feb73b59f8af JSON: {'aftermath': 'victory', 'increment_ly': False, 'serialize_on_response': True}

Traceback (most recent call last):
File "/home/toconnell/kdm-manager-api/venv/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
 rv = self.dispatch_request()
File "/home/toconnell/kdm-manager-api/venv/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
 return self.view_functions[rule.endpoint](**req.view_args)
File "/home/toconnell/kdm-manager-api/app/utils/crossdomain.py", line 57, in wrapped_function
 resp = flask.make_response(func(*args, **kwargs))
File "/home/toconnell/kdm-manager-api/app/routes.py", line 523, in collection_action
 return asset_object.request_response(action)
File "/home/toconnell/kdm-manager-api/app/models/settlements/_settlement.py", line 4807, in request_response
 return super().request_response(action)
File "/home/toconnell/kdm-manager-api/app/models/_user_asset.py", line 823, in request_response
 method_response = method()
File "/home/toconnell/kdm-manager-api/app/models/settlements/_settlement.py", line 2270, in return_survivors
 self.add_defeated_monster(self.settlement['current_quarry'])
File "/home/toconnell/kdm-manager-api/app/models/settlements/_settlement.py", line 1172, in add_defeated_monster
 'type': monst_obj.type,
AttributeError: 'Monster' object has no attribute 'type'
toconnell commented 10 months ago

Fixed:

diff --git a/app/models/settlements/_settlement.py b/app/models/settlements/_settlement.py
index 32c5692..a9ed89f 100644
--- a/app/models/settlements/_settlement.py
+++ b/app/models/settlements/_settlement.py
@@ -1169,7 +1169,7 @@ class Settlement(UserAsset):
             'created_on': datetime.now(),
             'handle': monst_obj.handle,
             'name': monst_obj.name,
-            'type': monst_obj.type,
+            'type': monst_obj.asset.get('type', None),
             'raw_name': monster_string,
         }
         for a in ['comment', 'level']:
@@ -1185,7 +1185,7 @@ class Settlement(UserAsset):
             msg % (
                 flask.request.User,
                 monster_string,
-                monst_obj.type,
+                monst_obj.asset.get('type', None),
                 self.get_current_ly()
             )
         )
toconnell commented 10 months ago

Pushing this as a hotfix, since its application-breaking.