-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Epic 11.5 - Import APIs #36389
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
Epic 11.5 - Import APIs #36389
Conversation
|
Thanks for the pull request, @cmltaWt0! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo 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:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the prototype Max!
One high-level direction question for @ormsbee about whether to combine these models with my legacy library import models. If he thinks they should stay separate, then @cmltaWt0 I have some data model comments for this PR.
| status = models.CharField( | ||
| max_length=100, | ||
| choices=CourseToLibraryImportStatus.choices, | ||
| default=CourseToLibraryImportStatus.PENDING | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have django-user-tasks for situations where we need to track that status of a Celery task and associate it with a user. Example - CourseExport
Would you be able to leverage that library as the basis for this?
| course_ids = models.TextField( | ||
| blank=False, | ||
| help_text=_('Whitespace-separated list of course keys for which to compute grades.'), | ||
| validators=[validate_course_ids] | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have one course per model instance. That way, this could be a LearningContextKeyField, and we'd have simpler validation and querying of this table. It will also make it easier to manage these tasks in Django admin if each one is associated with a single course.
If it makes this PR easier, you can assume that we are importing one course at a time. If it becomes important, we can implement multi-course import later at the REST API layer, and have a separate task model to track it.
| help_text=_('Whitespace-separated list of course keys for which to compute grades.'), | ||
| validators=[validate_course_ids] | ||
| ) | ||
| library_key = models.CharField(max_length=100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this a ForeignKey to ContentLibrary (or even LearningPackage). That gets us a few benefits:
- We get more efficient JOINs when querying
- We get database-level validation that we this model points at a valid learning package
| validators=[validate_course_ids] | ||
| ) | ||
| library_key = models.CharField(max_length=100) | ||
| source_type = models.CharField(max_length=30) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is source_type for?
| ) | ||
| library_key = models.CharField(max_length=100) | ||
| source_type = models.CharField(max_length=30) | ||
| metadata = models.JSONField(default=dict, blank=True, null=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is metadata for?
| Represents a component version that has been imported into a content library. | ||
| This is a many-to-many relationship between a component version and a course to library import. | ||
| """ | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us also add an FK to Component. That way, we can declare that component and library_import are unique_together.
I believe source_usage_key and library_import can also be declared as unique_together.
In other words, we assert that for any given library import event, the source block is unique, and the destination block is unique.
| return cls.objects.filter(id=import_id).first() | ||
|
|
||
|
|
||
| class ComponentVersionImport(TimeStampedModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Soon we will need to support container imports as well. When that time comes, were you thinking that we'd have a separate ContainerImport model? Or, should we generalize this model into PublishableEntityImport?
| @@ -0,0 +1,74 @@ | |||
| """ | |||
| Models for the course to library import app. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that I was quite insistent earlier that this app should explicitly focus on course-to-library imports. As I've worked on the legacy library migration, though, I'm realizing I may have been wrong about that. I see a lot of parallels between these models, and the legacy-lib-to-library models in my PR.
@ormsbee , do you think it would be reasonable to consider this djangoapp as a general import_to_learning_package application? The models would be something like:
class LegacyContentImportStatus(UserTaskStatus): ...
class LegacyContentImportSource(Model):
context_key = LearningContextKeyField(...) # course or legacy lib
authoritative_import = FK(LegacyContentToLearningPackageImport, null=True) # where to forward content to, if applicable
class LegacyContentToLearningPackageImport(Model):
source = FK(LegacyContentImportSource)
import = OneToOneField(LearningPackageImport)
class LearningPackageImport(Model):
target = FK(LearningPackage) # destination lib (or, in the future, learning-core course?)
target_collection = FK(Collection, null=True) # if applicable
class LegacyContentToPublishableEntityImport(Model):
package_migration = FK(LegacyContentToLearningPackageMigration)
source = UsageKeyField()
target = FK(PublishableEntity)
class Meta:
unique_together = [("package_migration", "source"), ("package_migration", "target")]b9e7dab to
7f9ae62
Compare
|
Per today's meeting, marking this as ready for review. Testing is happening now, bug fixes may be added in the coming days. |
7f9ae62 to
270b825
Compare
|
Sandbox deployment successful 🚀 |
4c2caef to
6ad5283
Compare
|
Sandbox deployment successful 🚀 |
|
Sandbox deployment successful 🚀 |
|
Sandbox deployment successful 🚀 |
|
@cmltaWt0 @NiedielnitsevIvan I am currently reviewing this. Please rebase when you get a chance. |
* feat: [AXM-1607] create initial DB layer * refactor: [AXM-1607] resolve lint errors, clean up code & add migrations * refactor: [AXM-1607] simplify raw user_id in admin & improve validation by checking for duplicate keys * refactor: [AXM-1607] lint fixes #2 --------- Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* feat: [AXM-1621] add staged content creation * refactor: [AXM-1621] revert unnecessary changes & functions refactor * feat: [AXM-1621] add CourseToLibraryImport creation & update + refactor to process multiple course ids --------- Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* feat: [AXM-1614] add course to library import feature
* feat: [AXM-1726] add container feature for import * refactor: [AXM-1726] post-review changes --------- Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* feat: [AXM-1635] create block importing route
* feat: [AXM-1780] add static tabs importing * refactor: [AXM-1780] rename to --------- Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* feat: REST API to get and create imports * test: add tests for new APIs
* refactor: refactor import creation api and task * test: refactor and improve tests * style: fix code style * refactor: refactor relation between CourseToLibraryImport and StagedContent * refactor: fix tests after refactoring * refactor: add CourseToLibraryImport relation to ContentLibrary * feat: add ContentLibraryFactory * test: refactor tests after change relations * feat: add CANCELED status * refactor: rename app, refactor models and Python APIs * fix: fix REST APIs after refactoring * fix: fix tests after refactoring * test: add LearningPackageFactory * style: remove extra import * chore: update migration
Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* feat: add admin action to import course to library * refactor: [AXM-1807] finish actions, refactor validation & purpose uniq --------- Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* fix: fix deadlock when import created from admin panel * refactor: rename celery task
…2631) Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
41f1d89 to
aa35955
Compare
|
Sandbox deployment successful 🚀 |
Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
|
Sandbox deployment successful 🚀 |
|
@NiedielnitsevIvan to help me review this, could you add details to the PR description on:
|
|
@kdmccormick Of course, here are Postman collections for these new APIs, just add the bearer token and everything should work. @cmltaWt0 is the author of this PR, so I can't update the description right now, so I'll describe it here for now. Instructions for testing the django admin workflow:
|
|
@NiedielnitsevIvan I would like to review the schema of the REST API, but that is hard to do just by reverse engineering the python code and the postman collection. Could you list out the new URLs and their methods? For example: https://github.com/openedx/edx-platform/blob/master/cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py#L4 Just put them in a PR comment for now, and once we are in agreement, you can move them into a code comment. |
Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
|
Sandbox deployment successful 🚀 |
d578dd3 to
ffe6598
Compare
|
@kdmccormick Oh, sorry, I misunderstood you a bit, here are the schemas of the new REST APIs:
|
|
Oh, you already have these docstrings in the code @NiedielnitsevIvan , sorry, not sure how I missed that. I'll comment on them there. |
|
Closed in favor of #36725 |
This has been broken into smaller PRs:
This PR contributes to EPIC 11.5: Import Course to Library API.
Accompanied ADR: #36545
@NiedielnitsevIvan @ormsbee @kdmccormick FYI