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 Sheet: cannot remove quarry #20

Closed toconnell closed 4 years ago

toconnell commented 4 years ago

From user email

[5af899b28740d936be7dbcd6] has submitted an error report!

The report goes as follows: Can't remove a quarry selected by error (Phoenix)

ERROR INFO:

Settlement OID: 5f81e719651593558f63e1ab

https://api.kdm-manager.com/settlement/rm_monster/5f81e719651593558f63e1ab

settlements object 'Yoffroia' [5f81e719651593558f63e1ab] Unable to process 'rm_monster' operation on asset: {'name': 'Phoenix', 'sort_order': 5, 'misspellings': ['PHONIEX'], 'node': 3, 'sub_type': 'quarry', 'type': 'monsters', 'type_pretty': 'Monsters', 'sub_type_pretty': 'Quarry', 'selector_text': 'Phoenix', 'handle': 'phoenix', 'levels': 3}

Looks like rm_monster() might be having some timing issues or maybe is POSTing twice?

toconnell commented 4 years ago

Looks like we're getting pranked by some older code that checks asset dictionaries' type value and is unaware of the new, more specific _subtype:

From the rm_monster() method of the Settlement object:

        # figure out what type it is or die trying
        m_type = m_dict['type']
        if m_type == 'quarry':
            target_list = self.settlement['quarries']
        elif m_type == 'nemesis':
            target_list = self.settlement['nemesis_monsters']
        else:
            raise utils.InvalidUsage(
                "%s Unable to process 'rm_monster' operation on asset: %s" % (
                    self, m_dict
                )
            )

I'm thinking that the fix here is probably just to switch to _subtype, but I kind of want to meditate on that before I pull the trigger.

toconnell commented 4 years ago

Updated the error to be more descriptive:

image

toconnell commented 4 years ago

This is resolved:

@@ -820,27 +821,43 @@ class Settlement(models.UserAsset):
         m_dict = self.Monsters.get_asset(monster_handle)

         # figure out what type it is or die trying
-        m_type = m_dict['type']
+        m_type = m_dict['sub_type']