-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: add management command for course prompts #28
Conversation
parser.add_argument( | ||
'--pre_message', | ||
dest='pre_message', | ||
help='message to prepend to course topics', | ||
) | ||
|
||
parser.add_argument( | ||
'--skills_descriptor', | ||
dest='skills_descriptor', | ||
help='message that describes skill structure' | ||
) | ||
|
||
# post-message | ||
parser.add_argument( | ||
'--post_message', | ||
dest='post_message', | ||
help='message to append to course topics', | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having three separate args for the messages, I'm wondering if it would be possible to use string formatting instead. This way, one message block could be passed in, and then the topics could be added to that string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either is fine. The string template seems fine, but we should leave a detailed explanation about the desired format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opted to leave this as is for now, but left a note describing the required structure.
skills_message = skills_descriptor + json.dumps(course_dict) | ||
|
||
# finally, create list of prompt messages and save | ||
prompt_messages = [pre_message, skills_message, post_message] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested if this format of message actually saves. When we were manually adding these, it took a bit of wrangling to get the json format correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something you can verify when manually testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, trying to do that now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Json formatting looks great, tested locally to confirm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
1fdb76a
to
9253edc
Compare
) | ||
|
||
@staticmethod | ||
def _get_discovery_api_client(username): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coverage is down because this function isn't being tested - I'm not really sure it's worth mocking everything in here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel like we need to do that.
""" | ||
Returns an API client which can be used to make Catalog API requests. | ||
""" | ||
User = get_user_model() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason not to use the OAuthAPIClient
with the BACKEND_SERVICE_EDX_OAUTH2_KEY
and BACKEND_SERVICE_EDX_OAUTH2_SECRET
settings instead of impersonating a user?
Is this a pattern we have elsewhere? Because it strikes me as a unexpected to use an existing account to make calls to the LMS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did find it elsewhere, this is ripped from the catalog app in edx-platform: https://github.com/openedx/edx-platform/blob/92731be0dc69d82cc4ec5b9c511e86df9aa9e632/openedx/core/djangoapps/catalog/utils.py#L51-L60.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Those changes eventually lead back to openedx/public-engineering#37, which says, "We will be switching usages of the old client to OAuthAPIClient as part of this removal."
Ed Zeracor left a comment, "In some cases the request is on the behalf of the user and we are passing JOTs around. We will still need to do this, but the current client doesn’t have an interface for supporting JOTs", which I think was the case for the catalog service. I imagine that's why it was implemented this way.
I'd lean toward using the OAuthAPIClient
, since it seems like the intended direction. It sounds like to me that the catalog service was implemented this way because the existing code wasn't well supported by OAuthAPIClient
, but this is new code. Registrar has an example of calling discovery with OAuthAPIClient
- it doesn't look any more complex.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh interesting find. I can try and look into using the OAuthAPIClient, I wasn't finding the credentials I needed so I wasn't sure if I would need to create them in discovery admin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use the OauthAPIClient. Opting to use the discovery-worker
credentials.
course_key = CourseKey.from_string(course_run_id) | ||
|
||
# discovery API requires course keys, not course run keys | ||
course_id = f'{course_key.org}+{course_key.course}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you've run a query to get the list of courses that have skills. Do any of them use the old style course IDs (e.g. edX/DemoX.1/2014
)? If so, will those calls to Discovery fail because you're constructing a course key in the new style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of them have the old style of course ID! I do see that as an area for improvement, but I think we are safe for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thank you. What do you think about leaving a comment that this only supports new style keys - seems like something one could overlook in the future.
parser.add_argument( | ||
'--pre_message', | ||
dest='pre_message', | ||
help='message to prepend to course topics', | ||
) | ||
|
||
parser.add_argument( | ||
'--skills_descriptor', | ||
dest='skills_descriptor', | ||
help='message that describes skill structure' | ||
) | ||
|
||
# post-message | ||
parser.add_argument( | ||
'--post_message', | ||
dest='post_message', | ||
help='message to append to course topics', | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either is fine. The string template seems fine, but we should leave a detailed explanation about the desired format.
) | ||
|
||
@staticmethod | ||
def _get_discovery_api_client(username): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel like we need to do that.
skills_message = skills_descriptor + json.dumps(course_dict) | ||
|
||
# finally, create list of prompt messages and save | ||
prompt_messages = [pre_message, skills_message, post_message] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something you can verify when manually testing?
70b9094
to
26b511a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just had one clarifying question and can then approve! :)
skills_message = skills_descriptor + json.dumps(course_dict) | ||
|
||
# finally, create list of prompt messages and save | ||
prompt_messages = [pre_message, skills_message, post_message] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
26b511a
to
d84dbc3
Compare
d84dbc3
to
2d8d29d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
MST-2164
This PR adds a management command that generates a new set of course prompts given a list of course ids.