Skip to content
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

Ensure contentnode.mark_complete() happens when File updated #4697

Conversation

nucleogenesis
Copy link
Member

@nucleogenesis nucleogenesis commented Aug 30, 2024

Summary

Description of the change(s) you made

  • Adds regression test that fails due to the bug
  • Updates the FileSerializer#update method to call mark_complete() on the File's content node
  • Creates a Change update event to ensure the front-end stays up-to-date when the contentnode is complete
  • Uses UpdateModelMixin in the FileViewSet ensuring that the File instance is saved, resulting in contentnode having its relation to the File updated

Screenshots (if applicable)

Does this introduce any tech-debt items?


Reviewer guidance

How can a reviewer test these changes?

  • Set a default channel-level License and Copyright Holder (or just do the Public Domain license)
  • Import files to that channel
  • Wait a few seconds (until the top spinner is done spinning)
  • See that the nodes have not become "Incomplete" because they are, indeed, complete now that they have a file

At a high level, the issue was that a "Content Node" is not complete without a file - but the order of operations goes that we first create the contentnode, then upload the file and associate it with the contentnode. So, until we perform that second bit of the operation the contentnode is "incomplete" without the file.

Here, we now check that the file being added makes the node complete and if it does, we update the client accordingly so that the user doesn't see the incomplete flag unnecessarily.

References

Closes #4644

Contributor's Checklist

PR process:

  • If this is an important user-facing change, PR or related issue the CHANGELOG label been added to this PR. Note: items with this label will be added to the CHANGELOG at a later time
  • If this includes an internal dependency change, a link to the diff is provided
  • The docs label has been added if this introduces a change that needs to be updated in the user docs?
  • If any Python requirements have changed, the updated requirements.txt files also included in this PR
  • Opportunities for using Google Analytics here are noted
  • Migrations are safe for a large db

Studio-specifc:

  • All user-facing strings are translated properly
  • The notranslate class been added to elements that shouldn't be translated by Google Chrome's automatic translation feature (e.g. icons, user-generated text)
  • All UI components are LTR and RTL compliant
  • Views are organized into pages, components, and layouts directories as described in the docs
  • Users' storage used is recalculated properly on any changes to main tree files
  • If there new ways this uses user data that needs to be factored into our Privacy Policy, it has been noted.

Testing:

  • Code is clean and well-commented
  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Any new interactions have been added to the QA Sheet
  • Critical and brittle code paths are covered by unit tests

Reviewer's Checklist

This section is for reviewers to fill out.

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@nucleogenesis nucleogenesis requested a review from rtibbles August 30, 2024 22:04
@nucleogenesis nucleogenesis marked this pull request as ready for review September 5, 2024 17:36
Copy link
Member Author

@nucleogenesis nucleogenesis left a comment

Choose a reason for hiding this comment

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

Idk why there are misc formatting changes - I didn't catch them when making my commit. So - if they don't jive w/ our tooling I need to talk to my IDE about how it's formatting my Python code


if results.contentnode:
results.contentnode.refresh_from_db()
if not len(results.contentnode.mark_complete()):
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we be handling this any differently? Basically mark_complete returns List<errors> when it is incomplete, is there anything I should do here w/ the information if there are issues?

Comment on lines +75 to +80
generate_update_event(
results.contentnode.id,
CONTENTNODE,
{"complete": True},
channel_id=results.contentnode.get_channel_id(),
),
Copy link
Member Author

Choose a reason for hiding this comment

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

Just basically copied this from the content node serializer _ensure_complete method and tweaked it to fit in here. Is there anything I've missed here that should be done/handled differently?

)
list_serializer_class = BulkListSerializer


def retrieve_storage_url(item):
""" Get the file_on_disk url """
"""Get the file_on_disk url"""
Copy link
Member Author

Choose a reason for hiding this comment

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

Hm... seems my formatter got aggressive here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that this was applied by pre-commit - I just accepted whatever pre-commit did thinking that it rewrote things related to my particular changes and didn't realize it was linting the whole file.


self.assertEqual(complete_except_no_file.complete, False)

models.Change.create_change = MagicMock()
Copy link
Member

Choose a reason for hiding this comment

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

You should do this as a mock.patch call:

with mock.patch("contentcuration.viewsets.file.Change") as ChangeMock:
        self.sync_changes(
            [generate_update_event(file.id, FILE, {"contentnode": complete_except_no_file.id}, channel_id=self.channel.id)],
        )

        self.assertTrue(ChangeMock.create_change.called)

FileViewset mixes in UpdateModelMixin in place of BulkUpdateMixin to
resolve primary issue, but this results in needing to call on_update
directly to avoid duplicate content_ids
@nucleogenesis nucleogenesis force-pushed the fix--contentnode-incompleted-by-file-update branch from 2e65bc7 to 84520f0 Compare September 16, 2024 20:09
@rtibbles rtibbles merged commit 0e1154f into learningequality:unstable Sep 16, 2024
13 checks passed
@akolson akolson mentioned this pull request Sep 18, 2024
@akolson akolson mentioned this pull request Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unstable - Seeing the 'Incomplete' icon for each new resource I upload
2 participants