Closed toconnell closed 2 years ago
Yeah, so _init_assetcollections() gets called before normalize() and we're feeding in a raw settlement attribute, which is a bad pattern, so the solution here is probably going to swap in a _getversion() call...?
Alright, this is fixed in dev, so I'm closing the ticket, but this needs more regression testing before it goes out the door.
diff --git a/app/models/settlements.py b/app/models/settlements.py
index 2935bef..14e8e2a 100644
--- a/app/models/settlements.py
+++ b/app/models/settlements.py
@@ -163,15 +163,19 @@ class Settlement(models.UserAsset):
err = "Settlement object must be loaded before assets can init!"
raise AttributeError(err)
+ # set versions first, since this is used by the get_versions() method
+ # that gets called to get assets at the settlement's version
+ self.Versions = versions.Assets()
+
self.Campaigns = campaigns.Assets()
- self.Endeavors = endeavors.Assets(self.settlement['version'])
+ self.Endeavors = endeavors.Assets(self.get_version(str))
self.Events = events.Assets()
self.Expansions = expansions.Assets()
self.FightingArts = fighting_arts.Assets()
- self.Gear = gear.Assets(self.settlement['version'])
- self.Resources = resources.Assets(self.settlement['version'])
+ self.Gear = gear.Assets(self.get_version(str))
+ self.Resources = resources.Assets(self.get_version(str))
self.Innovations = innovations.Assets()
- self.Locations = locations.Assets(self.settlement['version'])
+ self.Locations = locations.Assets(self.get_version(str))
self.Macros = macros.Assets()
self.Milestones = milestone_story_events.Assets()
self.Monsters = monsters.Assets()
@@ -182,7 +186,6 @@ class Settlement(models.UserAsset):
self.Survivors = survivors.Assets()
self.SurvivorColorSchemes = color_schemes.Assets()
self.SurvivorStatusFlags = status_flags.Assets()
- self.Versions = versions.Assets()
self.WeaponMasteries = weapon_masteries.Assets()
self.StrainMilestones = strain_milestones.Assets()
@@ -3752,9 +3755,20 @@ class Settlement(models.UserAsset):
return TL
- def get_version(self):
+ def get_version(self, return_type=object):
""" Returns the version object. """
- return self.Versions.get_asset(self.settlement['version'])
+
+ # set a default:
+ version_object = self.Versions.get_asset('core_1_3')
+
+ # override the default if the value exists
+ if hasattr(self.settlement, 'version'):
+ version_object = self.Versions.get_asset(self.settlement['version'])
+
+ # handle 'return_type' kwarg
+ if return_type == str:
+ return version_object['handle']
+ return version_object
Seems like we need to update the baseline() method?