Skip to content

fix: fix race condition where library is not in the store yet#826

Open
marslanabdulrauf wants to merge 3 commits into
mainfrom
marslan/12267-git-auto-export-missing-repo
Open

fix: fix race condition where library is not in the store yet#826
marslanabdulrauf wants to merge 3 commits into
mainfrom
marslan/12267-git-auto-export-missing-repo

Conversation

@marslanabdulrauf

Copy link
Copy Markdown
Contributor

What are the relevant tickets?

https://github.com/mitodl/hq/issues/12267

Description (What does it do?)

This pull request improves the reliability of exporting courses and libraries to GitHub by introducing better error handling for cases where content is not yet available in the database due to transaction timing. It adds a custom exception, ensures Celery tasks are dispatched only after database commits, and updates error handling in utility and task functions.

How can this be tested?

  1. Make sure it setup properly and configurations are correct
  2. Creating a new library should always create new repository
  3. Library repository's readme should have correct studio url

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the robustness of the ol_openedx_git_auto_export plugin when exporting newly-created courses/libraries to GitHub by handling “content not found (yet)” scenarios and deferring certain Celery dispatches until after DB commit, reducing transaction-timing races.

Changes:

  • Introduces ContentNotFoundError and updates get_content_info to raise it when courses/libraries can’t be found (including handling ContentLibraryNotFound from the v2 libraries API).
  • Updates Celery tasks to treat missing content as a non-fatal/expected condition (logging and skipping/returning cleanly).
  • Defers the library v2 “create repo + export” task dispatch using transaction.on_commit(...) to avoid running before the creating transaction commits.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/ol_openedx_git_auto_export/ol_openedx_git_auto_export/utils.py Raises a plugin-specific not-found exception for v1/v2 library and course lookups.
src/ol_openedx_git_auto_export/ol_openedx_git_auto_export/tasks.py Handles ContentNotFoundError in async tasks; adjusts Studio URL path composition for repo description.
src/ol_openedx_git_auto_export/ol_openedx_git_auto_export/signals.py Uses transaction.on_commit for v2 library creation task dispatch to prevent pre-commit races.
src/ol_openedx_git_auto_export/ol_openedx_git_auto_export/exceptions.py Adds the new ContentNotFoundError exception type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ol_openedx_git_auto_export/ol_openedx_git_auto_export/tasks.py
@arslanashraf7

Copy link
Copy Markdown
Contributor

@marslanabdulrauf is this ready for review? Could you please add the Needs review label to the PR if so?

@arslanashraf7 arslanashraf7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM with a small comment 👍


# Determine URL path based on content type
url_path = f"{content_info['content_type']}/{context_key_str}"
url_path = f"authoring/{content_info['content_type']}/{context_key_str}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My understanding is that this is only for informational purposes. Or is there more to it?

nit because this impacts only repo description change in my opinion: But in any case, I think this should be configurable because this value comes from infra, and it can change over time. So, making it configurable would allow us to keep up to date with the original value in infra without any code change and a new plugin deployment. This could be a new setting that defaults to authoring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes it is only for informational purposes.

/authoring is usually hardcoded in ol-infrastructure as well, no variable there.

image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, that's True. But imagine this scenario:

If they change the /authoring to something like /author. What will we need? 1) We will need to update this plugin code and change this line. 2) Deploy a new plugin on PyPI. 3) Change the plugin pin in infra. 4) Rebuild the Open edX instance deployment.

Whereas if this were a configurable setting in the plugin, we would need only: 1) update the config value to /author in infra; 2) rebuild the Open edX instance.

That being said, this is still a nit, so it's up to you to make this change or merge as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants