Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

RunPython migrations are broken with VersionedForeignKey fields #62

Open
ezheidtmann opened this issue Feb 28, 2015 · 3 comments
Open

Comments

@ezheidtmann
Copy link
Contributor

I'm trying to write a data migration for my app, and receiving the "not a Versionable" error when I read any VersionedForeignKey fields from models retrieved with the apps.get_model() recommended in Django docs. For example, this code is inside a RunPython migration:

Thing = apps.get_model('myapp', 'Thing')
mything = Thing.objects.current.first()
thing.vfk_field # throws TypeError("It seems ...")

I'm not sure whether this is the fault of Django migrations or of CleanerVersion.

I set a breakpoint inside versions/models.py at line 619 and I find that my target objects have made-up types:

(Pdb) type(current_elt).mro()
[<class 'Color'>, <class 'django.db.models.base.Model'>, <type 'object'>]
(Pdb) apps.get_model('rms', 'color').mro()
[<class 'rms.models.Color'>, <class 'versions.models.Versionable'>, <class 'rms.models.Term'>, <class 'django.db.models.base.Model'>, <type 'object'>]

Additionally, in this context there is no Model.objects.current and no Model.objects.as_of because objects is not a VersionedManager.

I don't know what the right thing to do is here. In my project, I can avoid writing a data migration today but I will probably need one later.

@qrilka
Copy link

qrilka commented Feb 20, 2016

Did you find any way around this?

@ezheidtmann
Copy link
Contributor Author

I don't think so; I've moved on to other projects and as far as I can remember, I just avoided doing a proper data migration on that project.

@qrilka
Copy link

qrilka commented Feb 21, 2016

Thanks @ezheidtmann
And I have just gone with a manual way - using relation ids, not related instances themselves.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants