Skip to content

Error While Running forum_migrate_course_from_mongodb_to_mysql – MongoContent.DoesNotExist #211

Closed

Description

@hassan-raza-1

While executing the management command forum_migrate_course_from_mongodb_to_mysql, which is intended to migrate forum data from MongoDB to MySQL, the following error was encountered:

Traceback (most recent call last):
  File "/edx/app/edxapp/edx-platform/./manage.py", line 99, in <module>
    execute_from_command_line([sys.argv[0]] + django_args)
  ...
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.11/site-packages/forum/migration_helpers.py", line 128, in create_or_update_comment
    mongo_thread = MongoContent.objects.get(mongo_id=mongo_thread_id)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/edx/app/edxapp/venvs/edxapp/lib/python3.11/site-packages/django/db/models/query.py", line 637, in get
    raise self.model.DoesNotExist(
forum.backends.mysql.models.MongoContent.DoesNotExist: MongoContent matching query does not exist.

Could you please look into this issue.

Environment Details:
Platform: edX Staging
Branch: master
Command: forum_migrate_course_from_mongodb_to_mysql

Activity

  1. hassan-raza-1 commented on Jul 30, 2025

    @hassan-raza-1
    Author
  2. added
    bug
    release blocker
    on Jul 31, 2025
  3. taimoor-ahmed-1 commented on Aug 6, 2025

    @taimoor-ahmed-1
    Contributor

    This could potentially happen if the thread wasn't created before and since a comment needs its parent thread id for creation, the command breaks because the thread with that id isn't there. Have you tried running the command again?

    Also, was there any error in stack trace before this which could point to a thread not being created?

  4. hassan-raza-1 commented on Aug 7, 2025

    @hassan-raza-1
    Author

    Can we handle cases where comments have no corresponding thread ID, especially for the existing data? We haven't re-executed the command yet, but we can share the complete logs if needed to help with debugging.

    Also, there was no prior error in the stack trace indicating that the thread creation failed — this was the first point of failure we observed.

  5. taimoor-ahmed-1 commented on Aug 7, 2025

    @taimoor-ahmed-1
    Contributor

    yes complete logs might give us a hint. A comment can't technically be present without a thread so if that's the case then its probably a dangling comment and we could let it fail silently.

  6. hassan-raza-1 commented on Aug 7, 2025

    @hassan-raza-1
    Author

    You can find the log file in your mailbox.
    @AhtishamShahid , could you please share your thoughts on the dangling comment regarding whether we should allow it to fail silently?

  7. AhtishamShahid commented on Aug 7, 2025

    @AhtishamShahid
    Contributor

    We should prioritize that all data should be transferred even if it has broken relations, and there should be no data loss during the transfer process.

  8. taimoor-ahmed-1 commented on Aug 11, 2025

    @taimoor-ahmed-1
    Contributor

    It wouldn't make much sense to have dangling comments/replies to posts that don't actually exist and won't be shown on the FE to the end users. What do you think @regisb ?

    Also, my I couldn't find why this is happening in the first place i.e. a comment exists with a non-existent thread id in the mongodb.

  9. regisb commented on Aug 11, 2025

    @regisb
    Contributor

    My 2 cents:

    1. No, it doesn't make sense to have dangling comments without a corresponding thread.
    2. But the migration command should not fail on such comments. MongoDB is not a consistent database, so we should expect inconsistent data there.
    3. Such dangling comments should not be handled silently. We should log a warning with comment/thread details. (including ID)
  10. taimoor-ahmed-1 commented on Aug 11, 2025

    @taimoor-ahmed-1
    Contributor

    I agree that we can improve the command by implementing point number 3 suggested by Regis. If everyone is on the same page, I can spin up a PR real quick

  11. added 2 commits that reference this issue on Aug 12, 2025
    899728c
    ba01ff6
  12. AhtishamShahid commented on Aug 18, 2025

    @AhtishamShahid
    Contributor

    @taimoor-ahmed-1 Logging skipped comments sounds good. Please let me know when the fix is deployed.

  13. added 2 commits that reference this issue on Aug 18, 2025
    8d0b717
    714fe81
  14. added a commit that references this issue on Aug 26, 2025
    51ec507
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugrelease blocker

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions