End-to-End Testing and Adjustments for Backup#375
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. |
| if hasattr(version, 'containerversion'): | ||
| children_qs = ( | ||
| version.containerversion.entity_list.entitylistrow_set | ||
| .order_by("entity__key") | ||
| .values_list("entity__key", flat=True) | ||
| .distinct() | ||
| ) | ||
| children = list(children_qs) | ||
| container_table.add("children", children) |
There was a problem hiding this comment.
Please use an api module call here instead of iterating through the children like this.
|
A couple of things I've noticed with the test file:
|
ormsbee
left a comment
There was a problem hiding this comment.
Another thing that came up when I was looking at your output file is that the library itself already appends stuff to the key when new things are created. So while I think the hash code is still important to have for edge cases, I don't think it will be necessary most of time.
How about this?
- We still slugify all the identifiers for the purposes of normalizing case and getting rid of weird characters.
- We keep track of all the slugs we've written for filenames.
- If there's no naming conflict, we just write the slugs without the extra hashing.
- If there is a naming conflict, we append the identifier hash like before.
| # Generate the slugified hash for the component local key | ||
| # Example: if the local key is "my_component", the slugified hash might be "my_component_123456" | ||
| # It's a combination of the local key and a hash and should be unique | ||
| entity_slugify_hash = slugify_hashed_filename(entity.key) |
There was a problem hiding this comment.
Please don't do this, actually. Most of the key is already represented by the directory structure. Leaving it with the local_key here makes it easier to read.
There was a problem hiding this comment.
Got it. Changes applied
- Assign timestamps to ZIP resources (folders and files): - Entity TOML files use the latest version timestamp - Other resources use the system timestamp - Add new logic to define entity filenames: - Slugify all identifiers - Track all generated slugs - Use the slug directly if there is no naming conflict - If a conflict exists, fall back to a slugified hash of the version name
|
Thank you for your support, @ormsbee . I’ve applied the new logic for timestamp handling in zipfile resources and for filename generation. |
ormsbee
left a comment
There was a problem hiding this comment.
A couple of small requests. Thank you!
| if isinstance(content, str): | ||
| content = content.encode("utf-8") | ||
| zip_file.writestr(file_info, content or b"") | ||
| else: # explicitly an empty folder |
There was a problem hiding this comment.
Please don't assume that paths without suffixes mean it's a directory. It's entirely possible to have a file named README or Makefile or something along those lines. Please keep the folder creation as a separate method.
Also, please make sure this code still works if people make arbitrary subdirectories inside the static assets folder of components, e.g. static/images/diagrams/figure1.png
| A list of entity keys for all entities in the container version, ordered by entity key. | ||
| """ | ||
| return list( | ||
| container_version.entity_list.entitylistrow_set | ||
| .values_list("entity__key", flat=True) | ||
| .order_by("entity__key") |
There was a problem hiding this comment.
Container children are ordered. This should be ordered by order_num.
| container_version.entity_list.entitylistrow_set | ||
| .values_list("entity__key", flat=True) | ||
| .order_by("entity__key") | ||
| .distinct() |
There was a problem hiding this comment.
Having the same child multiple times is allowed (it's a little weird, but it's valid), so please remove the distinct().
- Introduce `add_file_to_zip` and `add_folder_to_zip` for clarity - Remove suffix-based directory detection (avoids misclassifying files like README or Makefile) - Improves support for empty directories and arbitrary subdirectories
|
Thank you again, @ormsbee . The new adjustments are available in the Test.zip v3 file. |
ormsbee
left a comment
There was a problem hiding this comment.
One small request that was my fault for not catching it much earlier. Otherwise, I think this is good to merge. Thank you!
| draft_version: Optional[PublishableEntityVersion], | ||
| published_version: Optional[PublishableEntityVersion]) -> str: |
There was a problem hiding this comment.
I'll merge this anyway, but a nit here to prefer the newer notation of PublishableEntityVersion | None for annotations generally.
There was a problem hiding this comment.
Got it, I took the opportunity to change the values.
| container_table.add("children", children) | ||
|
|
||
| unit_table = tomlkit.table() | ||
| unit_table.add("graded", True) |
There was a problem hiding this comment.
Sorry, this is my fault that I missed this the first time -- there's actually no additional metadata on Units yet. In the original ticket, I was using this field as a hypothetical example of where we would put extra fields defined on specific container types, but there are actually no other fields defined on Unit yet. Please get rid of this.
Resolves: #374
PR Description
This PR focuses on testing the backup functionality for a learning package that contains all types of libraries. The goal is to validate the end-to-end dump process and apply any necessary adjustments based on the results.
Acceptance Criteria
Input Learning Package
All Content
Collection Content
Dump File
Test.zip V1
Test.zip V2
Test.zip V3