netzkolchose / django-computedfields

Provides autogenerated autoupdated database fields for model methods.
MIT License
94 stars 14 forks source link

up pulling over multiple multi tables is not stable #93

Closed jerch closed 2 years ago

jerch commented 2 years ago

Repro from modified docs example:

# wrong order
>>> MultiC.objects.create()
<class 'klaus.models.MultiC'>
<class 'klaus.models.MultiB'> sub-c
<class 'klaus.models.MultiBase'> b
...
>>> active_resolver._querysets_for_update(MultiC,MultiC.objects.filter(pk=4))
OrderedDict([
    (<class 'klaus.models.MultiB'>,     [<QuerySet [<MultiB: MultiB object (4)>]>, {'comp'}]),
    (<class 'klaus.models.MultiBase'>,  [<QuerySet [<MultiBase: MultiBase object (4)>]>, {'comp'}])
])

# correct order
>>> MultiC.objects.create()
<class 'klaus.models.MultiC'>
<class 'klaus.models.MultiBase'> b
<class 'klaus.models.MultiB'> sub-c
...
>>> active_resolver._querysets_for_update(MultiC,MultiC.objects.filter(pk=4))
OrderedDict([
    (<class 'klaus.models.MultiBase'>,  [<QuerySet [<MultiBase: MultiBase object (4)>]>, {'comp'}]),
    (<class 'klaus.models.MultiB'>,     [<QuerySet [<MultiB: MultiB object (4)>]>, {'comp'}])
])

We lose somewhere in the resolver the ordering information, thus the cf comp on MultiC(MultiB(MultiBase)) wrongly get filled from MultiB execution.