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

Make LTI http service take an LTIRegistration #6596

Merged
merged 1 commit into from
Aug 27, 2024
Merged

Conversation

marcospri
Copy link
Member

@marcospri marcospri commented Aug 23, 2024

For:

Until now all call to LTIA API happen on the context of a launch so it made sense to always scope them to the registration of that launch.

In preparation for start fetching course rosters, likely on a celery task, outside the context of a launch, take an explicit registration for LTIA calls.

Testing

This should be just a pure refactor, lets sanity check the changes:

Until now all call to LTIA API happen on the context of a launch so it
made sense to always scope them to the registration of that launch.

In preparation for start fetching course rosters, likely on a celery
task, outside the context of a launch, take an explicit registration for
LTIA calls.
@@ -47,6 +50,7 @@ def read_result(self, grading_id) -> GradingResult:

try:
response = self._ltia_service.request(
self._lti_registration,
Copy link
Member Author

Choose a reason for hiding this comment

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

Pass the registration again on existing ltia_service calls.

@@ -10,6 +10,7 @@

from typing import TypedDict

from lms.models import LTIRegistration
Copy link
Member Author

Choose a reason for hiding this comment

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

This code is not really used in the code base yet, from the beginning on the same files (where GH doesn't allow me to post a comment):

Service to talk to the Name and Roles LTIA API.
We only implement this now as a way to obtain the LTI Advantage Complete
certification and it's not used anywhere in the codebase yet.	

@@ -97,7 +107,6 @@ def _get_new_access_token(self, scopes: list[str]) -> JWTOAuth2Token:

def factory(_context, request):
return LTIAHTTPService(
request.lti_user.application_instance.lti_registration,
Copy link
Member Author

Choose a reason for hiding this comment

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

In general I don't like the existing pattern of scoping services to one request, AI or similar.

They become only useful in one context when they could be more useful just passing more parameters to the relevant functions.

Here we are planning to call this from a celery task, for many different registrations.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. Services scoped to the request tend to accidentally become stateful, and later refactors or dependencies between services end up producing accidental crossed data or even memory leaks.

With truly stateless services where the contextual information is passed via method arguments, we could just have a single persistent instance shared by all requests, as you mentioned above.

@marcospri marcospri requested a review from acelaya August 26, 2024 07:51
@marcospri marcospri marked this pull request as ready for review August 26, 2024 07:54
@@ -97,7 +107,6 @@ def _get_new_access_token(self, scopes: list[str]) -> JWTOAuth2Token:

def factory(_context, request):
return LTIAHTTPService(
request.lti_user.application_instance.lti_registration,
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. Services scoped to the request tend to accidentally become stateful, and later refactors or dependencies between services end up producing accidental crossed data or even memory leaks.

With truly stateless services where the contextual information is passed via method arguments, we could just have a single persistent instance shared by all requests, as you mentioned above.

@marcospri marcospri merged commit e9976f3 into main Aug 27, 2024
9 checks passed
@marcospri marcospri deleted the ltia-refactor branch August 27, 2024 08:32
Copy link

sentry-io bot commented Sep 2, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

Did you find this useful? React with a 👍 or 👎

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.

2 participants