localwiki/localwiki — Issue #202: Explore automatic versioning of related models
Author: philipn
Created: 2012-02-24 04:20:24+00:00
State: open
Labels: versioning

@philipn: What we do with M2Ms to non-versioned models could be similar to what we do with FKs to non-versioned models: nothing, really. If you delete the FK-ed-to model and then try and access it from a historical instance, it just won't work. It might make sense to change this behavior, though, and automatically version all related models, always.

Versioning everything would fix the mystery factor a bit ("Why do I have to version Tag explicitly to get this to work?"). I'm not sure that there's a downside. What do you think?

The revert issue remains -- I'll add a keyword to revert_to to make it resurrect historical versions. What we do with relations doesn't much matter -- we can table that change for today.

-----

@mivanov: If the related model isnt versioned, does the relation get versioned? That's really what I think would be expected as it looks like part of the model? If we have to version the related model to get that to work, I think it does make sense to do it implicitly, but it definitely shouldn't revert those models by default if you didn't ask for that. That would really be mysterious and unexpected.

-----

@philipn: Yeah, I set up revert_to() to take a keyword argument, restore_relations=['field', 'names', 'here'], and it'll restore those particular field names during revert. So it's explicit.

-----

**Question:** should we automatically version related models?

Versioning related models automatically would:

1. Make M2M reverts act correctly when the M2M field is itself not versioned (if requested via ``revert_to(restore_related=['fieldname'])``).
2. Let us revert models even if they have a related attribute that's been deleted (see the logic in ``revert_to`` around reverting to a model, "Check that none of the attached, versioned related fields are currently deleted")
3. Prevent deleting a related model that's not explicitly versioned from deleting all of the historical instances during a deletion cascade. This is kind of expected behavior -- you shouldn't delete non-versioned models and expect everything to be okay. But changing this should be okay.