Skip to content

fix: issues related to course_id#109

Merged
Faraz32123 merged 3 commits intomasterfrom
fix/course_id_issues
Oct 17, 2024
Merged

fix: issues related to course_id#109
Faraz32123 merged 3 commits intomasterfrom
fix/course_id_issues

Conversation

@Faraz32123
Copy link
Copy Markdown
Contributor

@Faraz32123 Faraz32123 commented Oct 17, 2024

  • bypass searching course_id by thread/comment in mongo and then search it in mysql
  • convert course_id(str) into CourseKey before passing it to CourseWaffleFlag's is_enabled method as it expects CourseKey

@Faraz32123 Faraz32123 self-assigned this Oct 17, 2024
@Faraz32123 Faraz32123 force-pushed the fix/course_id_issues branch 2 times, most recently from 950bebd to 6197fbd Compare October 17, 2024 05:51
@Faraz32123 Faraz32123 marked this pull request as draft October 17, 2024 05:58
- bypass searching course_id by thread/comment in mongo and
then search it in mysql
- convert course_id(str) into CourseKey before passing it to
CourseWaffleFlag's is_enabled method as it expects CourseKey
@Faraz32123 Faraz32123 force-pushed the fix/course_id_issues branch from 6197fbd to 52fa5d1 Compare October 17, 2024 06:04
@Faraz32123 Faraz32123 marked this pull request as ready for review October 17, 2024 06:08
Comment thread forum/backends/mongodb/api.py Outdated
Comment thread forum/backends/mongodb/api.py Outdated
thread = CommentThread().get(thread_id)
if thread:
return thread.get("course_id")
except bason_errors.InvalidId:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In which case(s) is this exception happening?

Copy link
Copy Markdown
Contributor Author

@Faraz32123 Faraz32123 Oct 17, 2024

Choose a reason for hiding this comment

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

if we have id whose type is not objectId. Like we try to search thread in mongo first and then in mysql.
So in case of id from mysql, when it tries to find thread with id 1 in mongo, the error raises.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got it! Please add a comment :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

try:
thread = CommentThread().get(thread_id)
if thread:
return thread.get("course_id")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be: return thread["course_id"]? (likewise below)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In case of standalone threads, thread don't have course_id.
Just to avoid key error and returning None. Although we don't have standalone thread now as far as I know.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a comment to explain that. (and similar below)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@Faraz32123 Faraz32123 force-pushed the fix/course_id_issues branch from a3f2b47 to 6724b1b Compare October 17, 2024 08:35
@Faraz32123 Faraz32123 requested a review from regisb October 17, 2024 08:38
Comment thread forum/backend.py Outdated
Comment on lines +17 to +21
# pylint: disable=C0415,E0401
from opaque_keys.edx.locator import CourseKey # type: ignore[import-not-found]

if isinstance(course_id, str):
course_id = CourseKey.from_string(course_id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we move opaquekey import to try block or simply remove try-except?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, moved the import to the try-except block.

@Faraz32123 Faraz32123 merged commit 279ca59 into master Oct 17, 2024
@regisb regisb deleted the fix/course_id_issues branch October 17, 2024 21:32
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.

3 participants