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

feat: add management command for course prompts #28

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

alangsto
Copy link
Member

@alangsto alangsto commented Oct 18, 2023

MST-2164

This PR adds a management command that generates a new set of course prompts given a list of course ids.

Comment on lines 41 to 58
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',
)
Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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]
Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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!

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@alangsto alangsto force-pushed the alangsto/add_management_command branch 4 times, most recently from 1fdb76a to 9253edc Compare October 18, 2023 14:48
)

@staticmethod
def _get_discovery_api_client(username):
Copy link
Member Author

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.

Copy link
Member

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()
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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}'
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Comment on lines 41 to 58
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',
)
Copy link
Member

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):
Copy link
Member

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]
Copy link
Member

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?

@alangsto alangsto force-pushed the alangsto/add_management_command branch 5 times, most recently from 70b9094 to 26b511a Compare October 19, 2023 16:13
Copy link
Member

@varshamenon4 varshamenon4 left a 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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@alangsto alangsto force-pushed the alangsto/add_management_command branch from 26b511a to d84dbc3 Compare October 20, 2023 14:26
@alangsto alangsto force-pushed the alangsto/add_management_command branch from d84dbc3 to 2d8d29d Compare October 20, 2023 14:28
Copy link
Member

@varshamenon4 varshamenon4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@alangsto alangsto merged commit 5224f66 into main Oct 20, 2023
5 of 7 checks passed
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

Successfully merging this pull request may close these issues.

3 participants