django-simple-history icon indicating copy to clipboard operation
django-simple-history copied to clipboard

Issue with mypy, django-stubs and simple-history

Open jlariza opened this issue 1 year ago • 1 comments

Good day,

We have a project that uses mypy to check the types across the project. MyPy's check was working with no issue. However, we installed simple_history and created an abstract class to add historical data to some of our models. This the class we defined:

class HistoricModel(models.Model):
    history = HistoricalRecords(inherit=True)
    class Meta:
        abstract = True

After we added it to some of our models, We started to get the following messages

Couldn't resolve related manager for relation '<MyModel>'

when running the mypy check.

The ones that show this message are models with a ForeignKey relationship to one of the models that is inherit from HistoricModel.

Why is this error appearing? How may we fix it or bypass it?

Thank you,

jlariza avatar Sep 21 '23 21:09 jlariza

is this when accessing the related history records? or is django-simple-history interfering with other typing? would you be able to create an example project? i don't think i have enough of an understanding to suggest a way to bypass.

django-simple-history implements its own 'descriptor' (a Django internals concept) to make the history records available. descriptors are part of the magic django-stubs is doing bookkeeping for.. i imagine django-simple-history would need to somehow extend the descriptor typing mechanism for this to all work correctly together.

macro1 avatar Apr 25 '24 03:04 macro1