-
Notifications
You must be signed in to change notification settings - Fork 18
feat: api for updating children in container [FC-0083] #292
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
feat: api for updating children in container [FC-0083] #292
Conversation
|
Thanks for the pull request, @navinkarkera! 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. |
af80981 to
d2bf63d
Compare
7e127d0 to
7552d7a
Compare
pomegranited
left a comment
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.
@navinkarkera I really like how you added get_next_entity_list and the different ChildrenEntitiesAction -- very clean!
But I've got some concerns about keeping the APIs consistent. What do you think?
pomegranited
left a comment
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.
👍 left some stylistic nits, but this looks good @navinkarkera :)
- I tested this with openedx/edx-platform#36434 (review)
- I read through the code
-
I checked for accessibility issues by using my keyboard to navigateN/A - Includes documentation
- User-facing strings are extracted for translation
| last_entities = last_version.entity_list.entitylistrow_set.values_list( | ||
| "entity_id", | ||
| "entity_version_id" | ||
| ) | ||
| # append given publishable_entities_pks and entity_version_pks | ||
| publishable_entities_pks = [entity[0] for entity in last_entities] + publishable_entities_pks | ||
| entity_version_pks = [ # type: ignore[operator, assignment] | ||
| entity[1] | ||
| for entity in last_entities | ||
| ] + entity_version_pks |
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.
nit: Can we get around this little bit of awkwardness (and still keep the query data small) by using only() instead of values_list?
| last_entities = last_version.entity_list.entitylistrow_set.values_list( | |
| "entity_id", | |
| "entity_version_id" | |
| ) | |
| # append given publishable_entities_pks and entity_version_pks | |
| publishable_entities_pks = [entity[0] for entity in last_entities] + publishable_entities_pks | |
| entity_version_pks = [ # type: ignore[operator, assignment] | |
| entity[1] | |
| for entity in last_entities | |
| ] + entity_version_pks | |
| last_entities = last_version.entity_list.entitylistrow_set.only('entity_id', 'entity_version_id') | |
| # append given publishable_entities_pks and entity_version_pks | |
| publishable_entities_pks = [entity.entity_id for entity in last_entities] + publishable_entities_pks | |
| entity_version_pks = [ # type: ignore[operator, assignment] | |
| entity.entity_version_id | |
| for entity in last_entities | |
| ] + entity_version_pks |
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.
Nice! Updated.
ormsbee
left a comment
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.
At a high level, I'm not clear on why we need knowledge of append/remove/replace at this level. As someone who hasn't kept up with the edx-platform, it seems like that could all be done there, leaving the Learning Core API a bit dumber and less opinionated about how the next entity list is calculated.
That being said, I'll defer to you folks on the necessity of this, since you're much more deeply into this right now. If we do decide to pull it out, that can be done as a follow-up thing anyhow. We've marked all the container stuff as experimental anyhow.
I have two relatively small concerns that I'd like to see addressed:
- That we're using an API call with
get_that has a side-effect of creating something. - A possible edge case condition around deleted children in the count. This might just be my misunderstanding of the code.
Please address these and squash, and I'll merge.
| if container_version is None: | ||
| raise ContainerVersion.DoesNotExist # This container has not been published yet, or has been deleted. | ||
| assert isinstance(container_version, ContainerVersion) | ||
| return container_version.entity_list.entitylistrow_set.count() |
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.
Does this work in the edge case where we've soft-deleted a child element and published that soft-delete, but haven't removed that element from the container? Don't we need to filter those out of the entry list?
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.
Ah great catch, thank you @ormsbee . We should add a test for this case too.
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.
Yes, thank you. Updated: a11f1bd
| REPLACE = "replace" | ||
|
|
||
|
|
||
| def get_next_entity_list( |
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.
get_ implies a read operation, when this is actually creating something. Please rename it to clearly indicate that it creates something.
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.
Updated: e1222ea
| entity_version_pks: list[int | None] = [None] * len(publishable_entities_pks) # type: ignore[no-redef] | ||
| if entities_action == ChildrenEntitiesAction.APPEND: | ||
| # get previous entity list rows | ||
| last_entities = last_version.entity_list.entitylistrow_set.only("entity_id", "entity_version_id") |
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 forgot something: the existing entity_list needs to be ordered by order_num to maintain the original sort order, both here and with REMOVE below.
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.
@ormsbee The only reason was to avoid (re)fetching children entities before calling |
ormsbee
left a comment
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.
Please squash and add any relevant context to your commit message, and I'll merge it. Were you planning to add a version bump with this, or to wait for other changes to land before incrementing?
0c7730a to
6d288d2
Compare
Modify children components of a container via API. It is possible to move add and remove children section to edx-platform but it would require additional call to fetch existing children from database before calculating new children list.
6d288d2 to
b1abf34
Compare
|
@ormsbee Thanks!, squashed, updated version and ready to merge. |
|
FYI @navinkarkera it looks like this PR missed a migration for a change to ordering - see #298 (comment) |
|
@bradenmacdonald Oops, missed it. |
Description:
Updates
create_next_container_versionapi to handle addition or removal of children entities.Related to: openedx/frontend-app-authoring#1706 and openedx/frontend-app-authoring#1705
Private-ref: https://tasks.opencraft.com/browse/FAL-4109Test instructions: