dym/django-offline-messages

Django 1.10 start up failure

Closed this issue · 3 comments

With django-offline-messages installed, Django 1.10 fails to start. The surface error message is:

File ".../django/db/models/fields/related.py", line 567, in resolve_related_fields
ValueError: Related model u'auth.User' cannot be resolved

however, this seems to just be a side effect of an earlier failure that results in settings.AUTH_USER_MODEL not getting resolved from u'auth.User' to the actual User model. If the user FK in the OfflineMessage model is temporarily hardcoded to User (after importing User), an underlying error is revealed on start up:

File ".../offline_messages/models.py", line 52, in __getattr__
    return getattr(self.get_query_set(), name)
AttributeError: 'OfflineMessageQuerySetManager' object has no attribute 'name'

The __getattr__ method on OfflineMessageManager tries to get a name attribute on OfflineMessageQuerySetManager because it's not (yet) on OfflineMessageManager, but it's not on OfflineMessageQuerySetManager either. Django does set name on the manager but only on the __init__ of an instance. I haven't looked into the detail but it would seem in 1.10 this is now too late. It might or might not be related to 1.10 changes in custom manager inheritance.

One way of avoiding the need for the __getattr__ method would be to generate the Manager from the QuerySet using the from_queryset class method, available from Django 1.7 (so backwards compatible for all currently supported Django versions).

This handles making the QuerySet filters available on the Manager without the need for __getattr__ and allows Django 1.10 to start up. I.e. replacing OfflineMessageManager with:

OfflineMessageManager = models.Manager.from_queryset(OfflineMessageQuerySetManager)

I haven't yet checked whether everything still works as normal with this change as there are some other Django 1.10 changes I need to handle in my codebase first, but I thought I'd raise this issue now.

@dym - there hasn't been activity on this project for a while, is it still a maintained project, would you accept PRs?

dym commented

@nealtodd Hello, this is not an active project for me.
If you think the package is worth trying and all the rest looks good for you, I'll gladly accept PR with fixes and will update pypi with new package version.

Thanks @dym, I'll make a PR for this if I decide to continue using the package after testing. Cheers.

Closing as I've removed non-active packages in my project in the run up to Django 2.0 when Py 2 support drops. The fix mentioned in the issue will work for anyone wanting to fork or submit a PR.

Thanks for the project @dym