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

Settlement: get_available_endeavors() error #24

Closed toconnell closed 3 years ago

toconnell commented 3 years ago

User OID: 5d69efb76515934a1280b57f Method: GET URL: http://api.kdm-manager.com/settlement/get_campaign/5f0b67496515930160fb1858 JSON: None

Traceback (most recent call last):
File "/home/toconnell/kdm-manager-api/venv/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
 rv = self.dispatch_request()
File "/home/toconnell/kdm-manager-api/venv/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
 return self.view_functions[rule.endpoint](**req.view_args)
File "/home/toconnell/kdm-manager-api/app/utils/crossdomain.py", line 56, in wrapped_function
 resp = flask.make_response(func(*args, **kwargs))
File "/home/toconnell/kdm-manager-api/app/routes.py", line 497, in collection_action
 return asset_object.request_response(action)
File "/home/toconnell/kdm-manager-api/app/models/settlements.py", line 4324, in request_response
 return Response(response=self.serialize('campaign'), status=200, mimetype="application/json")
File "/home/toconnell/kdm-manager-api/app/models/settlements.py", line 548, in serialize
 available_endeavors, available_endeavor_count = self.get_available_endeavors()
File "/home/toconnell/kdm-manager-api/app/models/settlements.py", line 2366, in get_available_endeavors
 events = current_ly.get('settlement_event', None)
AttributeError: 'NoneType' object has no attribute 'get'
toconnell commented 3 years ago

This is actually a problem with the return from _get_timelineyear():

image

toconnell commented 3 years ago

Looks like root cause was auto-advancing the LY to a non-existent LY. From the prod logs:

[2020-11-09 00:12:43] INFO:     settlements object 'Fireshrine' [5f0b67496515930160fb1858] event: Brianna, Milo, Respite and Venicia returned to the settlement in victory.
[2020-11-09 00:12:43] INFO:     settlements object 'Fireshrine' [5f0b67496515930160fb1858] event: jcastle99@gmail.com set settlement current Lantern Year to 31.
[2020-11-09 00:12:43] INFO:     Saved settlements object 'Fireshrine' [5f0b67496515930160fb1858] to mdb.settlements successfully!
[2020-11-09 00:12:43] INFO:     Saved settlements object 'Fireshrine' [5f0b67496515930160fb1858] to mdb.settlements successfully!
toconnell commented 3 years ago
--- a/app/models/settlements.py
+++ b/app/models/settlements.py
@@ -1580,7 +1580,8 @@ class Settlement(models.UserAsset):

         # 7.) increment LY, if necessary
         if self.params.get('increment_ly', False):
-            self.set_current_ly(self.get_current_ly() + 1)
+            if not self.get_current_ly() >= self.get_max_ly():
+                self.set_current_ly(self.get_current_ly() + 1)