openedx / course-discovery

Service providing access to consolidated course and program metadata
https://edx-discovery.readthedocs.io/en/latest/
GNU Affero General Public License v3.0
57 stars 173 forks source link

fix: use "price" in ecommerce data loader #4450

Closed tecoholic closed 1 month ago

tecoholic commented 1 month ago

Description

The Django Oscar upgrade of ecommerce changed the item's price field from price_excl_tax to just price causing the EcommerceApi data loader to fail.

This commit handled the exception and falls back to the 'price' value.

Ref: https://github.com/openedx/ecommerce/pull/4050

Additional information

The same as #4291.

Testing instructions

Reproduce Issue

  1. Setup Tutor 18 (Redwood) dev env with the plugins ecommerce and discovery enabled
  2. Clone course-discovery.
  3. Add a tutor mount for the course-discovery.
  4. Create a course or import the demo course.
  5. Setup admin user for ecommerce and discovery
  6. Add a course seat in http://ecommerce.local.edly.io:8130/courses/ for the test course
  7. Run the following from Discovery Shell to set the ecommerce API url. NOTE: trying the same in Discovery admin fails due to URL validation.
    from course_discovery.apps.core.models import Partner
    p = Partner.objects.get(short_code="dev")
    p.ecommerce_api_url = "http://ecommerce:8130/api/v2/"
    p.save()
  8. Run ./manage.py refresh_course_metadata --partner dev. It should fail with the KeyError price_excl_tax.

Testing the fix from PR

  1. Checkout the PR branch
  2. Run ./manage.py refresh_course_metadata --partner dev again. This time, it should run successfully.
openedx-webhooks commented 1 month ago

Thanks for the pull request, @tecoholic!

What's next?

Please work through the following steps to get your changes ready for engineering review:

:radio_button: Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

:radio_button: Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

:radio_button: Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

:radio_button: Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/course-discovery-admins. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

:bulb: As a result it may take up to several weeks or months to complete a review and merge your PR.

tecoholic commented 1 month ago

@AfaqShuaib09 Thanks for the suggestion. I have applied it to the PR.

tecoholic commented 1 month ago

@AfaqShuaib09 I raised the with the fix for just the one place where I encountered an error. If other functions also need to be updated, I can do that. But I am not sure what those functions do. So, anyone can confirm those functions need to be updated, I can recreate update the PR accordingly.

Ali-D-Akbar commented 1 month ago

@AfaqShuaib09 I raised the with the fix for just the one place where I encountered an error. If other functions also need to be updated, I can do that. But I am not sure what those functions do. So, anyone can confirm those functions need to be updated, I can recreate update the PR accordingly.

Hi there! I do agree with Afaq since this field was previously added in the aforementioned closed PR. Also, I believe adding it in update_entitlement and validate_stockrecord is also the right way since both of these functions are used in EcommerceApi Data Loader and having the correct price value should be the right thing else it will result in failure again.

tecoholic commented 1 month ago

@AfaqShuaib09 @Ali-D-Akbar Hi, thanks for confirming. I have updated the references in the mentioned functions and the mock data as well. Can you kindly review?

Note: All the CI checks for Python 3.8 seems to be failing due to a setuptools error. I want to highlight that course-discovery tutor template for redwood uses Python 3.12. So we can safely disregard the 3.8 failures.

tecoholic commented 1 month ago

@Ali-D-Akbar Hi, can you kindly review this change and merge it?

cc: @AfaqShuaib09

tecoholic commented 1 month ago

@Ali-D-Akbar Thank you.