-
-
Notifications
You must be signed in to change notification settings - Fork 535
Incorrect Error Message for Duplicate Module Name #3879
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
Open
mrkeshav-05
wants to merge
15
commits into
OWASP:main
Choose a base branch
from
mrkeshav-05:fix/issue-3860
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+464
−62
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
422f6c5
update code for showing error
mrkeshav-05 c59fc1e
apply suggestions
mrkeshav-05 7975e2e
Merge branch 'main' into fix/issue-3860
mrkeshav-05 df2ec9c
Merge branch 'main' into fix/issue-3860
mrkeshav-05 e925902
Merge branch 'main' into fix/issue-3860
mrkeshav-05 3c9b197
Merge branch 'main' into fix/issue-3860
mrkeshav-05 8d7626e
update code with graphql error handler
mrkeshav-05 8efc201
update tests
mrkeshav-05 3b00fed
make check-test and change msg
mrkeshav-05 e33e9dc
apply suggestions
mrkeshav-05 a11f6c1
Merge branch 'main' into fix/issue-3860
mrkeshav-05 3fa17d9
Merge branch 'main' into fix/issue-3860
mrkeshav-05 66b6bc5
Merge remote-tracking branch 'upstream/main' into fix/issue-3860
mrkeshav-05 6f0cf39
apply suggestions
mrkeshav-05 82f074a
make check-test
mrkeshav-05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,9 @@ | |
| import strawberry | ||
| from django.core.exceptions import ObjectDoesNotExist, PermissionDenied, ValidationError | ||
| from django.db import transaction | ||
| from django.db.utils import IntegrityError | ||
| from django.utils import timezone | ||
| from graphql import GraphQLError | ||
|
|
||
| from apps.github.models import User as GithubUser | ||
| from apps.mentorship.api.internal.nodes.module import ( | ||
|
|
@@ -114,18 +116,29 @@ def create_module(self, info: strawberry.Info, input_data: CreateModuleInput) -> | |
| program.ended_at, | ||
| ) | ||
|
|
||
| module = Module.objects.create( | ||
| name=input_data.name, | ||
| description=input_data.description, | ||
| experience_level=input_data.experience_level.value, | ||
| started_at=started_at, | ||
| ended_at=ended_at, | ||
| domains=input_data.domains, | ||
| labels=input_data.labels, | ||
| tags=input_data.tags, | ||
| program=program, | ||
| project=project, | ||
| ) | ||
| try: | ||
| with transaction.atomic(): | ||
| module = Module.objects.create( | ||
| name=input_data.name, | ||
| description=input_data.description, | ||
| experience_level=input_data.experience_level.value, | ||
| started_at=started_at, | ||
| ended_at=ended_at, | ||
| domains=input_data.domains, | ||
| labels=input_data.labels, | ||
| tags=input_data.tags, | ||
| program=program, | ||
| project=project, | ||
| ) | ||
| except IntegrityError as e: | ||
cubic-dev-ai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| error_message = str(e) | ||
| if "unique_module_key_in_program" in error_message: | ||
| msg = "This module name already exists in this program." | ||
| raise GraphQLError( | ||
| msg, | ||
| extensions={"code": "VALIDATION_ERROR", "field": "name"}, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see you using 'VALIDATION_ERROR' anywhere right now 🤔 |
||
| ) from e | ||
| raise | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if module.experience_level not in program.experience_levels: | ||
| program.experience_levels.append(module.experience_level) | ||
|
|
@@ -392,7 +405,18 @@ def update_module(self, info: strawberry.Info, input_data: UpdateModuleInput) -> | |
| mentors_to_set = resolve_mentors_from_logins(input_data.mentor_logins) | ||
| module.mentors.set(mentors_to_set) | ||
|
|
||
| module.save() | ||
| try: | ||
| with transaction.atomic(): | ||
| module.save() | ||
| except IntegrityError as e: | ||
| error_message = str(e) | ||
| if "unique_module_key_in_program" in error_message: | ||
| msg = "This module name already exists in this program." | ||
| raise GraphQLError( | ||
| msg, | ||
| extensions={"code": "VALIDATION_ERROR", "field": "name"}, | ||
| ) from e | ||
| raise | ||
|
|
||
| if module.experience_level not in module.program.experience_levels: | ||
| module.program.experience_levels.append(module.experience_level) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.