mitodl / edx-platform

The Open edX platform, the software that powers edX!
http://open.edx.org/
GNU Affero General Public License v3.0
6 stars 1 forks source link

TypeError: Field 'id' expected a number but got <django.contrib.auth.models.AnonymousUser object at 0x7f2ab6... #301

Closed sentry-io[bot] closed 1 year ago

sentry-io[bot] commented 1 year ago

Sentry Issue: OPENEDX-RESIDENTIAL-50B

KeyError: 'grades_cache.course-v1:MITx+8.01+2022_Fall'
  File "lms/djangoapps/grades/models.py", line 620, in read
    prefetched_grades = get_cache(cls._CACHE_NAMESPACE)[cls._cache_key(course_id)]

PersistentCourseGrade.DoesNotExist: PersistentCourseGrade matching query does not exist.
  File "lms/djangoapps/grades/course_grade_factory.py", line 50, in read
    return self._read(user, course_data)
  File "lms/djangoapps/grades/course_grade_factory.py", line 152, in _read
    persistent_grade = PersistentCourseGrade.read(user.id, course_data.course_key)
  File "lms/djangoapps/grades/models.py", line 629, in read
    return cls.objects.get(user_id=user_id, course_id=course_id)
  File "django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "django/db/models/query.py", line 435, in get
    raise self.model.DoesNotExist(

TypeError: Cannot cast AnonymousUser to int. Are you trying to use it in place of User?
  File "django/db/models/fields/__init__.py", line 1823, in get_prep_value
    return int(value)
  File "django/contrib/auth/models.py", line 420, in __int__
    raise TypeError('Cannot cast AnonymousUser to int. Are you trying to use it in place of User?')

TypeError: Field 'id' expected a number but got <django.contrib.auth.models.AnonymousUser object at 0x7f2ab6c48f10>.
(32 additional frame(s) were not displayed)
...
  File "django/db/models/sql/query.py", line 1370, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "django/db/models/sql/query.py", line 1216, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "django/db/models/lookups.py", line 25, in __init__
    self.rhs = self.get_prep_lookup()
  File "django/db/models/fields/related_lookups.py", line 117, in get_prep_lookup
    self.rhs = target_field.get_prep_value(self.rhs)
  File "django/db/models/fields/__init__.py", line 1825, in get_prep_value
    raise e.__class__(
pdpinch commented 1 year ago

Possibly related, judging by the error message: https://github.com/openedx/tcril-engineering/issues/443#issuecomment-1296986508

asadali145 commented 1 year ago

Hey @pdpinch, Before Olive, we can simply set a feature flag settings.FEATURES[“ASSUME_ZERO_GRADE_IF_ABSENT_FOR_ALL_TESTS”] to True. This will enable zero grades feature that is also the default behaviour in Olive. It will resolve the above issue.

We do not need to do anything with the Milestones app if we haven't enabled Entrance Exams for the anonymously available courseware. Everything should work fine after the above feature flag.

@blarghmatey Could you please guide me like where to add the above feature flag for residential MITx? Thanks

asadali145 commented 1 year ago

Could someone from @mitodl/devops help with the above setting?

arslanashraf7 commented 1 year ago

Could someone from @mitodl/devops help with the above setting?

This is the idea i had about these but definitely wait on devops to see if there might be other places for this.

There are two differnt files for the features settings for MITx. I think this will nee to be added in both or we can add it in staging first, test it and then add to producution file too. The references are mitx/common_values.yml.tmpl and mitx-staging/common_values.yml.tmpl.

blarghmatey commented 1 year ago

For residential the setting can be added to the common_settings.yml.tmpl in the mitx and mitx-staging directories under https://github.com/mitodl/ol-infrastructure/tree/main/src/bilder/images/edxapp/templates/edxapp