Regression in QuerySet MRO #594

Closed
opened 2022-01-03 14:57:26 +01:00 by nik · 5 comments
Owner

Apparently, the change in !2497 broke the method resolution order for the queryset of groups, or something like that.

│ Traceback (most recent call last):                                                                                                                  │
│   File "/usr/local/lib/python3.9/dist-packages/django/core/handlers/exception.py", line 47, in inner                                                │
│     response = get_response(request)                                                                                                                │
│   File "/usr/local/lib/python3.9/dist-packages/django/core/handlers/base.py", line 181, in _get_response                                            │
│     response = wrapped_callback(request, *callback_args, **callback_kwargs)                                                                         │
│   File "/usr/local/lib/python3.9/dist-packages/sentry_sdk/integrations/django/views.py", line 67, in sentry_wrapped_callback                        │
│     return callback(request, *args, **kwargs)                                                                                                       │
│   File "/usr/local/lib/python3.9/dist-packages/rules/contrib/views.py", line 231, in _wrapped_view                                                  │
│     return view_func(request, *args, **kwargs)                                                                                                      │
│   File "/usr/local/lib/python3.9/dist-packages/aleksis/apps/chronos/views.py", line 42, in all_timetables                                           │
│     teachers, classes, rooms = get_teachers(user), get_classes(user), get_rooms(user)                                                               │
│   File "/usr/local/lib/python3.9/dist-packages/aleksis/apps/chronos/util/chronos_helpers.py", line 89, in get_classes                               │
│     Group.objects.for_current_school_term_or_all()                                                                                                  │
│   File "/usr/local/lib/python3.9/dist-packages/django/db/models/manager.py", line 85, in manager_method                                             │
│     return getattr(self.get_queryset(), name)(*args, **kwargs)                                                                                      │
│ AttributeError: 'CTEQuerySet' object has no attribute 'for_current_school_term_or_all'
Apparently, the change in !2497 broke the method resolution order for the queryset of groups, or something like that. ```plain │ Traceback (most recent call last): │ │ File "/usr/local/lib/python3.9/dist-packages/django/core/handlers/exception.py", line 47, in inner │ │ response = get_response(request) │ │ File "/usr/local/lib/python3.9/dist-packages/django/core/handlers/base.py", line 181, in _get_response │ │ response = wrapped_callback(request, *callback_args, **callback_kwargs) │ │ File "/usr/local/lib/python3.9/dist-packages/sentry_sdk/integrations/django/views.py", line 67, in sentry_wrapped_callback │ │ return callback(request, *args, **kwargs) │ │ File "/usr/local/lib/python3.9/dist-packages/rules/contrib/views.py", line 231, in _wrapped_view │ │ return view_func(request, *args, **kwargs) │ │ File "/usr/local/lib/python3.9/dist-packages/aleksis/apps/chronos/views.py", line 42, in all_timetables │ │ teachers, classes, rooms = get_teachers(user), get_classes(user), get_rooms(user) │ │ File "/usr/local/lib/python3.9/dist-packages/aleksis/apps/chronos/util/chronos_helpers.py", line 89, in get_classes │ │ Group.objects.for_current_school_term_or_all() │ │ File "/usr/local/lib/python3.9/dist-packages/django/db/models/manager.py", line 85, in manager_method │ │ return getattr(self.get_queryset(), name)(*args, **kwargs) │ │ AttributeError: 'CTEQuerySet' object has no attribute 'for_current_school_term_or_all'
Author
Owner

assigned to @nik

assigned to @nik
Author
Owner

created merge request !2505 to address this issue

created merge request !2505 to address this issue
Author
Owner

mentioned in merge request !2505

mentioned in merge request !2505
Author
Owner

What the…?

In [4]: hasattr(Group.objects, "for_current_school_term_or_all")
Out[4]: True

In [5]: Group.objects.for_current_school_term_or_all
Out[5]: <bound method BaseManager._get_queryset_methods.<locals>.create_method.<locals>.manager_method of <django.db.models.manager.GroupManagerFromGroupQuerySet object at 0x7f4001bcc670>>

In [6]: Group.objects.for_current_school_term_or_all()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-ae8498ba2fbd> in <module>
----> 1 Group.objects.for_current_school_term_or_all()

~/AlekSIS/AlekSIS/apps/official/AlekSIS-Core/.venv/lib/python3.9/site-packages/django/db/models/manager.py in manager_method(self, *args, **kwargs)
     83         def create_method(name, method):
     84             def manager_method(self, *args, **kwargs):
---> 85                 return getattr(self.get_queryset(), name)(*args, **kwargs)
     86             manager_method.__name__ = method.__name__
     87             manager_method.__doc__ = method.__doc__

AttributeError: 'CTEQuerySet' object has no attribute 'for_current_school_term_or_all'
What the…? ```plain In [4]: hasattr(Group.objects, "for_current_school_term_or_all") Out[4]: True In [5]: Group.objects.for_current_school_term_or_all Out[5]: <bound method BaseManager._get_queryset_methods.<locals>.create_method.<locals>.manager_method of <django.db.models.manager.GroupManagerFromGroupQuerySet object at 0x7f4001bcc670>> In [6]: Group.objects.for_current_school_term_or_all() --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-6-ae8498ba2fbd> in <module> ----> 1 Group.objects.for_current_school_term_or_all() ~/AlekSIS/AlekSIS/apps/official/AlekSIS-Core/.venv/lib/python3.9/site-packages/django/db/models/manager.py in manager_method(self, *args, **kwargs) 83 def create_method(name, method): 84 def manager_method(self, *args, **kwargs): ---> 85 return getattr(self.get_queryset(), name)(*args, **kwargs) 86 manager_method.__name__ = method.__name__ 87 manager_method.__doc__ = method.__doc__ AttributeError: 'CTEQuerySet' object has no attribute 'for_current_school_term_or_all' ```
Owner

mentioned in commit fb05e99a62

mentioned in commit fb05e99a621a3c760c45a80911be5e9437fe6d3d
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aleksis/AlekSIS-Core#594
No description provided.