-
Notifications
You must be signed in to change notification settings - Fork 28
fix(graphql): Validate origin_branch on BranchCreate(#5674) #6703
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
base: stable
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
from infrahub.core.branch import Branch | ||
from infrahub.database import retry_db_transaction | ||
from infrahub.exceptions import InfrahubError | ||
from infrahub.graphql.context import apply_external_context | ||
from infrahub.graphql.types.context import ContextInput | ||
from infrahub.log import get_logger | ||
|
@@ -70,6 +71,15 @@ async def mutate( | |
|
||
model = BranchCreateModel(**data) | ||
await apply_external_context(graphql_context=graphql_context, context_input=context) | ||
if model.origin_branch: | ||
if model.origin_branch == model.name: | ||
raise InfrahubError(f"A branch cannot originate from itself: {model.name}") | ||
origin_branch_obj = await Branch.get_by_name(db=graphql_context.db, name=model.origin_branch) | ||
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. this call will raise a |
||
if not origin_branch_obj: | ||
raise InfrahubError(f"Origin branch '{model.origin_branch}' does not exist.") | ||
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 know the bug report does not make this clear, but we actually only allow branching from the default branch. It would be good to check for that in this conditional, something like if not origin_branch_obj.is_default:
raise ProcessingError(...) |
||
|
||
|
||
|
||
|
||
if background_execution or not wait_until_completion: | ||
workflow = await graphql_context.active_service.workflow.submit_workflow( | ||
|
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.
this is not a valid import. I'd suggest replacing
InfrahubError
withProcessingError