nautobot-app-golden-config icon indicating copy to clipboard operation
nautobot-app-golden-config copied to clipboard

updated safer migration

Open whitej6 opened this issue 1 year ago • 9 comments

whitej6 avatar Sep 07 '22 16:09 whitej6

Tests are failing. Saying validated_save Attribute doesn't exist on DGs.

jeffkala avatar Sep 12 '22 13:09 jeffkala

@glennmatthews I think the failure is from how I am interacting with the DynamicGroup model. I have always been told to not reference model code in migrations as it is dependent on that code not changing in later releases.

whitej6 avatar Sep 12 '22 13:09 whitej6

Oh right. In a migration you get a very bare-bones proxy of the model :-( https://docs.djangoproject.com/en/3.2/topics/migrations/#historical-models. So this approach won't work. You could call .clean() and .save() directly but that won't actually get into the real model's clean method even so, so I think this fix is DOA.

glennmatthews avatar Sep 12 '22 15:09 glennmatthews

Is there a post migration signal we can do or better to wrap in a management command?

whitej6 avatar Sep 12 '22 15:09 whitej6

@glennmatthews & @itdependsnetworks thoughts on adding this to the plugin config? https://docs.djangoproject.com/en/3.2/ref/signals/#post-migrate

Thought would be to query all the DGs and perform a validated_save() on them and if it fails we error out and provide output that informs the user to fix the specific DG?

whitej6 avatar Sep 12 '22 15:09 whitej6

https://nautobot.readthedocs.io/en/stable/plugins/development/#populating-extensibility-features is essentially this. :-)

glennmatthews avatar Sep 12 '22 16:09 glennmatthews

@whitej6 what should we do here?

itdependsnetworks avatar Sep 21 '22 13:09 itdependsnetworks

@itdependsnetworks I need to swap the updated migrations to what Glenn linked.

whitej6 avatar Sep 21 '22 13:09 whitej6

@glennmatthews can you take a peak?

whitej6 avatar Sep 30 '22 17:09 whitej6