Tags: esnet-security/SCRAM
Tags
fix(route_manager history): move history update to after model save (#… …160) We need to actually update the Entry change reason after we save the Entry model which then creates a history model for that change. Before, we were doing it in the serializer before the model is saved, which means that the query to the DB that looks for the appropriate historical_entry instance doesn't find anything because it's looking for the historical entry that hasn't been saved yet. This is related to #138 and actually, I think, would have fixed it, but we came at it from a different (and frankly, I guess, wrong) angle. Because update_change_reason only **_edits_** a historical entry, not create a new one, but I was originally assuming that this function call was what created the historical entry in the first place. In #138 we "fixed" this issue by making sure that the database migrations went and edited all the history to have the default value which then means we technically were editing the comment for the wrong history entry.
fix(migrations): Fix REALLY broken historicalentry migration (#138) Wow, I screwed up. The migration default for route_manager_historicalentry wasn't the same as the one for route_manager_entry. Apparently, this is REALLY bad based off of how django-simple-history works, which you can see outlined [here](django-commons/django-simple-history#672). This adds a migration that nukes all history of the originating SCRAM instance field and sets it to what the default should have been. Then there is another migration that sets the value to what it should have been in the first place. We also don't pull in the settings value on the model anymore because that was also a terrible idea of mine. We now just set that on where we create the Entry model instance. This should fix issues related to re-blocking something that had already been in the database. Without this fix, you'll see 500 errors when trying to update an entry to re-block it with the following error: `AttributeError: 'NoneType' object has no attribute 'history_change_reason'`. This is because the simple history library tries to find the history record using ALL of the model attributes as an exact query, so if one of the attributes on the Real Model doesn't match what's in Historical Model, then you are in trouble land as it can't find the model. WHOOPSIE. --------- Co-authored-by: Sam Oehlert <soehlert@es.net>