feat: import sections, subsections, and units from TOML into Learning Core#392
Conversation
|
Thanks for the pull request, @dwong2708! 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. DetailsWhere 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. |
| try: | ||
| container = attrs["container"] | ||
| if "children" not in container: | ||
| raise ValueError("Missing 'children' in container") |
There was a problem hiding this comment.
These should raise serializers.ValidationError.
There was a problem hiding this comment.
Fixed. Thank yout.
| if not isinstance(children, list): | ||
| raise ValueError("'children' must be a list") |
There was a problem hiding this comment.
Generally, single-field validation is done with validate_<field_name> methods.
There was a problem hiding this comment.
Changes applied. Thank you.
| attrs["children"] = children | ||
| attrs.pop("container") # Remove the container field after processing | ||
| except ValueError as exc: | ||
| raise serializers.ValidationError({"key": str(exc)}) |
There was a problem hiding this comment.
Oh, I see, we're aggregating errors and re-raising. The nice thing about using separate validate_<field> methods is that it can surface multiple errors at the same time. This pattern you have here will short-circuit on the first error and hide the other ones.
There was a problem hiding this comment.
Yeah, good catch. I've added those errors in an array. Thank you.
| container_map = { | ||
| "section": "section", # name of the container class : name of the toml table | ||
| "subsection": "subsection", | ||
| "unit": "unit", |
There was a problem hiding this comment.
I'm not clear what the purpose of this map is, if all the values map to themselves?
There was a problem hiding this comment.
I thought the class name could be different from the TOML table value, but I changed it since it is the same value for now.
| if self.errors: | ||
| raise ValueError( | ||
| "Errors encountered during restore: " | ||
| + "; ".join([f"{err['file']}: {err['errors']}" for err in self.errors]) | ||
| ) |
There was a problem hiding this comment.
Please definitely put this in a log file instead of raising a big ValueError..
ormsbee
left a comment
There was a problem hiding this comment.
Wrote some inline comments earlier, wanted to make sure you saw this.
ormsbee
left a comment
There was a problem hiding this comment.
Minor request in terms of testing the publishing api change.
Are you planning to make more tests for zip uploads, e.g. writing out subdirectories that represent test use cases and then making an in-memory ZipFile of them in order to test that it uploads the way you expect?
| entity.learning_package_id, | ||
| last_version, | ||
| entity_rows, | ||
| entity_rows if entity_rows is not None else [], |
There was a problem hiding this comment.
Whenever you make an addition to another app's api.py file, please add a corresponding test for it. So in this case, please add a test case method that covers this alongside the other publishing api tests.
There was a problem hiding this comment.
Understood. I added the test case for it. Thank you
Hi Dave, yes. I plan to include those tests in my final PR |
Sorry, to clarify: Do you mean that you'll include those tests in the final version of this PR, or that you intend to add them in a follow-on PR? |
Oh, sorry for my previous message. I meant that I plan to add them in a follow-on PR |
Resolves: #381
Description
This PR enables importing sections, subsections, and units into Learning Core from the contents of a TOML file.
This ensures that library structures can be consistently restored from backup definitions.
Changes
publishing_api.create_next_container_versionto handle cases wherecontainer.versioning.latestisNone.Input
test2.zip
Django Admin Output
Publishable entities

Draft Change Logs

Containers

Entity Lists

Entity List Detail for Unit

Entity List Detail for Subsection

Entity List Detail for Section
