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

Pull more product data from the Learn API #193

Merged
merged 5 commits into from
Jan 13, 2025

Conversation

jkachel
Copy link
Collaborator

@jkachel jkachel commented Jan 7, 2025

What are the relevant tickets?

Closes mitodl/hq#6309

Description (What does it do?)

Expands the data retrieval from Learn to include:

  • Product name and description
  • Product price

This is used in the existing management command update_product_data, which will now update all of those fields in addition to the images. (It's also now named update_product_data.)

Since this is effectively all the relevant data for the product, this also adds an endpoint and a management command to do that specifically:

  • /api/v0/meta/products/preload/<system_slug>/<sku>/ will trigger a query to Learn to retrieve the data for the specified resource, and will create the product in UE if it's found in Learn but not in UE
  • import_product does this same thing, but as a management command.

The API endpoint is rate limited for unauthenticated users, and it calls the Learn API in real time. The use case is that the integrated system will ping this endpoint when a learner opens a resource page to make sure UE has a product for the resource. The API won't update a product that exists, and will return errors if the item isn't found via Learn's learning_resources API (so you can't just load whatever you want). The integrated system doesn't necessarily need to wait for the call to finish.

This also updates the data retrieval code to handle resource runs better. Prior to this, the code simply checked for the entire SKU in Learn (SKUs are generally the resource's readable ID). This is fine for a course or a program but not for a run of that program - the Learn API won't return data if you have a run in the readable ID. So, this now splits off the run and resource IDs so they can be matched separately.

Finally, this culls the traefik_test_request endpoint; we haven't supported Traefik in a while so this isn't particularly useful to have.

How can this be tested?

Create an Integrated System that matches a platform in Learn, and a product for that system that matches a resource. For example, create mitxonline and a product for course-v1:MITxT+14.100x+2T2025. Then, run update_product_data for this product. The product should be updated with the image data, as well as the pricing, title, and description from Learn.

Import a product using the command line: import_product mitxonline course-v1:MITxT+11.S952x+2T2022 (or similar). This should build out the product with the data from Learn.

Run the preload API on a SKU that does not yet exist: /api/v0/meta/product/preload/mitxonline/course-v1%3AMITxT%2B14.73x%2B1T2025/ This should build out a product with the data from Learn.

Run the last two for SKUs that don't match an integrated system or a resource that exists. You should see an appropriate error message.

  • Test SKUs for a resource that exists but with an invalid run (e.g. try course-v1:MITxT+24.118x+3T4096). The API will have data from Learn to work with in this case but it should still fail because the run shouldn't exist.

Additional Context

Maybe we want to restrict the preload API to require an API key or something since this could be used to generate products for things in Learn that shouldn't have them (or shouldn't have them quite yet).

This will take the highest price out of the prices that are captured by Learn. It will fall back to the resource price if the run doesn't have a price attached. Most (all?) things have two or fewer prices so this is fine, but if there's something with more than that, then that product should be managed manually. (We may want a flag for this in the product record - ideally these should update via scheduled task.)

…able ids, fall back to initial data

- The metadata retrieval is now in an api function so it's easier to test.
- Added a parser for readable ID - skus are generally readable IDs, but if we have a sku that's for a specific run, the learning_resources API won't know what to do with it.
- If the data returned from the API doesn't contain data, or doesn't contain _some_ data, fall back to the data that was in the product already.
- Added tests for API function
- Fixed some names (we're not just pulling image data now)
@jkachel jkachel added the Work in Progress Not done yet. label Jan 7, 2025
…spec; remove a test endpoint

- Pre-load API: a separate API that can be used to load and build a product for a given system and SKU
- Created a function to load the data from Learn for a given system and SKU (but just load it)
- Fixed some test issues
- Removed the traefik_test_request endpoint, since we're not doing Traefik at all now
- Added some settings for throttling
- Adds import_product management command to build out a product out of Learn data
- Renames update_product_image_data to update_product_data since it's not _just_ image data now
- Refactored all the Learn pulling code into api.get_product_metadata
- Updated the preload API to use the new stuff
no-verify, maybe that'll help with the formatting thing
@jkachel jkachel added Needs Review An open Pull Request that is ready for review and removed Work in Progress Not done yet. labels Jan 9, 2025
@jkachel jkachel marked this pull request as ready for review January 9, 2025 22:04
@cp-at-mit cp-at-mit self-assigned this Jan 10, 2025
@cp-at-mit cp-at-mit removed the Needs Review An open Pull Request that is ready for review label Jan 11, 2025
@jkachel jkachel merged commit 1f732ca into main Jan 13, 2025
7 checks passed
@jkachel jkachel deleted the jkachel/6309-add-more-metadata-pulling branch January 13, 2025 16:25
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