Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking context throws opaque_keys.InvalidKeyError with some enterprise URLs #31837

Open
rgraber opened this issue Feb 27, 2023 · 1 comment
Assignees

Comments

@rgraber
Copy link
Contributor

rgraber commented Feb 27, 2023

From an Enterprise ticket:
enterprise saw some stacktraces in the logs related to enterprise enrollments. we investigated to see what was up, found some tracking context stuff that seems to need a regex tweak. original trace and investigation below…

2023-01-17 19:48:09,379 WARNING 38198 [common.djangoapps.track.contexts] [user None] [ip 161.131.0.240] contexts.py:38 - unable to parse course_id "UCT+SMA/enroll"
Traceback (most recent call last):
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/opaque_keys/__init__.py", line 187, in from_string
    namespace, rest = cls._separate_namespace(serialized)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/opaque_keys/__init__.py", line 218, in _separate_namespace
    raise InvalidKeyError(cls, serialized)
opaque_keys.InvalidKeyError: <class 'opaque_keys.edx.keys.CourseKey'>: UCT+SMA/enroll
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/edx/app/edxapp/edx-platform/common/djangoapps/track/contexts.py", line 36, in course_context_from_url
    course_id = CourseKey.from_string(course_id_string)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/opaque_keys/__init__.py", line 196, in from_string
    return cls.deprecated_fallback._from_deprecated_string(serialized)
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.8/site-packages/opaque_keys/edx/locator.py", line 389, in _from_deprecated_string
    raise InvalidKeyError(cls, serialized)
opaque_keys.InvalidKeyError: <class 'opaque_keys.edx.locator.CourseLocator'>: UCT+SMA/enroll

Note on line 16 above, looks like we are not parsing the course key correctly

this is the regular expression involved in parsing the course key from the URL:

match = COURSE_REGEX.match(url)

it works out to ^(.*?/course(s)?/)(?!v[0-9]+/[^/]+)(?P<course_id>[^/+]+(/|+)[^/+]+(/|+)[^/?]+)

when passing an example from our logs: /enterprise/5d566680-12a8-4b85-89d8-d9eacbf0f9eb/course/WasedaX+SJB2-3.101x/enroll/ (using a tester like

)

we get a course_id of WasedaX+SJB2-3.101x/enroll hence the error.

@rgraber rgraber added the backlog To be put on a team's backlog or wishlist label Feb 27, 2023
@robrap robrap removed the backlog To be put on a team's backlog or wishlist label Apr 20, 2023
@jristau1984
Copy link
Contributor

@spencertiberi can you see if Enterprise can pick up this bug resolution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants