Can't subclass the Message model, MessageManager breaks

Issue #103 resolved
Dirk Groten created an issue

When subclassing Message and using the MessageManager as the objects manager, queries like inbox don't work:

class Message(postman.models.Message):
    name = CharField(max_length=80, blank=True)

    class Meta
        manager_inheritance_from_future = True  # to use postman's MessageManager

Then in a shell:

> ./manage.py makemigrations
> ./manage.py migrate
> ./manage.py shell
>>> Message.objects.inbox(user=some_user)

psycopg2.ProgrammingError: column core_message.id does not exist
LINE 1: ...L) GROUP BY "postman_message"."thread_id") PM ON ("core_mess...

Note: here core_message is my subclass.

I think this is due to the as_sql custom query method in query.py.

I'm using Django 1.11.12 with Postman 3.6.1

Comments (9)

  1. Dirk Groten reporter

    I'm now circumventing the problem by returning postman.models.Message instances for the QuerySet with selected_related('message') to follow through to my message model:

    class MessageManager(postman.models.MessageManager):
        def _folder(self, *args, **kwargs):
            return postman.models.Message.objects._folder(*args, **kwargs).selected_related('message')
    
    class Message(postman.models.Message):
        objects = MessageManager()
    

    A bit unfortunate, since now inbox, sent, etc... return instances of postman.models.Message and I have to do m.message.name to get to my added field. But works for now until we fix the issue.

  2. Patrick Samson repo owner
    • changed status to open

    PR merged, and slightly refined.
    Please confirm it works the same on your side.

  3. Log in to comment