You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using a historical model in djangorestframework versions 3.12.3 and newer you cannot use OrderingFilter for the ListAPIView. If so an exception get raised in the serializer.
To Reproduce
Steps to reproduce the behavior:
Create model with history.
Create djangorestframework serializer for HistoricalModel.
Create a ListAPIView with OrderingFilter.
Head over to a link (eg /api/systems/configs-history/36) and see the error message.
Reason of the bug (did some debugging for you):
The internals of OrderingFilter call getattr for history_object on the historical model class. This resolves to calling __get__ on HistoricalObjectDescriptor (there is some metaprogramming checking all attributes of the class) but because it was called on the class not the instance, this method fails because it doesn't account for the case where instance is None (ie a call made on the class instead of the instance).
Environment (please complete the following information):
OS: Debian 10
Browser: Firefox
Django Simple History Version: 3.0.0
Django Version: 2.2
Database Version postgresql: 11.11
Solution:
Solution should be simple if I understood it correctly, add if instance is None: return self to the __get__ function and djangorestframework continues without errors when it calls for the history_object on the model class. I will make a PR for that.
Workaround:
Internals are only called if ordering_fields are not specified. Specify them to get rid of the bug.
The text was updated successfully, but these errors were encountered:
Describe the bug
When using a historical model in djangorestframework versions 3.12.3 and newer you cannot use
OrderingFilter
for theListAPIView
. If so an exception get raised in the serializer.To Reproduce
Steps to reproduce the behavior:
/api/systems/configs-history/36
) and see the error message.example:
Expected behavior
No exception when you do this.
Error logs:
https://i.imgur.com/J1ga93D.png
https://termbin.com/9fzh
Reason of the bug (did some debugging for you):
The internals of
OrderingFilter
callgetattr
forhistory_object
on the historical model class. This resolves to calling__get__
onHistoricalObjectDescriptor
(there is some metaprogramming checking all attributes of the class) but because it was called on the class not the instance, this method fails because it doesn't account for the case where instance is None (ie a call made on the class instead of the instance).https://docs.python.org/3/reference/datamodel.html#object.__get__
This bug got introduced in:
encode/django-rest-framework#7609
Environment (please complete the following information):
Solution:
Solution should be simple if I understood it correctly, add
if instance is None: return self
to the__get__
function and djangorestframework continues without errors when it calls for thehistory_object
on the model class. I will make a PR for that.Workaround:
Internals are only called if ordering_fields are not specified. Specify them to get rid of the bug.
The text was updated successfully, but these errors were encountered: