tkhyn / django-gm2m

MIT License
36 stars 23 forks source link

Django loaddata broken (GM2MModel metaclass) #47

Closed schyffel closed 4 years ago

schyffel commented 4 years ago

I have a problem loading a migration fixture with GM2M-data. It seems to come down to gm2m.helpers.GM2MModelMetaclass. Basically, gm2m.helpers.GM2MModel tries to metaclass gm2m.helpers.Dummy, and then override that: GM2MModel.__bases__ = (models.Model,)

That is supposed to bypass the Django machinery, but that does not work on my setup, using Django 2.2 and python 3.6 or 3.7. Instead Django will do its thing, and while doing post_init it tries to do a lookup using the GM2MModelMetaclass, which fails with a TypeError: unhashable type.

I solved the problem locally by adding a hash method to GM2MModelMetaclass. That works for the migration of data, but I don't understand the mechanisms enough to propose that as a general solution.

def __hash__(cls): return hash(RECURSIVE_RELATIONSHIP_CONSTANT)

tkhyn commented 4 years ago

I think this is now fixed via PR #51 (and released in v1.1.1). Feel free to reopen if it is not the case