Skip to content

GraphQL 500 Internal Server Error : branchRuleDelete mutation

Summary

The GraphQL mutation branchRuleDelete caused a 500 Internal Server Error. The error was triggered due to an attempt to delete a Projects::BranchRule with an ID that does not exist in the database, resulting in an ActiveRecord::RecordNotFound exception.

Steps to Reproduce

  1. Execute the GraphQL mutation branchRuleDelete as shown below:

    mutation branchRuleDelete($input: BranchRuleDeleteInput!) {
      branchRuleDelete(input: $input) {
        branchRule {
          branchProtection {
            allowForcePush
          }
        }
        clientMutationId
        errors
      }
    }
  2. Use the following variables:

    {
      "input": {
        "id": "gid://gitlab/Projects::BranchRule/1"
      }
    }
  3. Observe that the system returns a 500 status code.

Example Project

  • Docker Image: Version 17.4.1-ce

Current Bug Behavior

  • The GraphQL mutation branchRuleDelete results in a 500 Internal Server Error.
  • The error indicates that the specified Projects::BranchRule could not be found, which results in an unhandled server-side failure.

Expected Correct Behavior

  • The expected result should be:
    • A 200 status code with either:
      • Successful deletion of the branch rule, or
      • An error object indicating that the branch rule does not exist, without causing an internal server failure.

Relevant Logs / Error Details

GraphQL Mutation Query:

"query": "mutation branchRuleDelete($input: BranchRuleDeleteInput!) { branchRuleDelete(input: $input) { branchRule { branchProtection { allowForcePush } } clientMutationId errors } }",
"variables": "{\"input\":{\"id\":\"gid://gitlab/Projects::BranchRule/1\"}}"

Error Trace:

ActiveRecord::RecordNotFound: Couldn't find Projects::BranchRule with 'id'=1

app/models/projects/branch_rule.rb:18:in `rescue in find'
app/models/projects/branch_rule.rb:13:in `find'
globalid (1.1.0) lib/global_id/locator.rb:129:in `locate'
globalid (1.1.0) lib/global_id/locator.rb:154:in `block in locate'
globalid (1.1.0) lib/global_id/locator.rb:166:in `unscoped'
globalid (1.1.0) lib/global_id/locator.rb:154:in `locate'
globalid (1.1.0) lib/global_id/locator.rb:16:in `locate'
globalid (1.1.0) lib/global_id/global_id.rb:49:in `find'
app/graphql/gitlab_schema.rb:100:in `find_by_gid'
lib/gitlab/graphql/authorize/authorize_resource.rb:49:in `find_object'
lib/gitlab/graphql/authorize/authorize_resource.rb:53:in `authorized_find!'
app/graphql/mutations/branch_rules/delete.rb:20:in `resolve'
graphql (2.3.15) lib/graphql/schema/resolver.rb:121:in `public_send'
graphql (2.3.15) lib/graphql/schema/resolver.rb:121:in `call_resolve'
graphql (2.3.15) lib/graphql/schema/mutation.rb:69:in `call_resolve'
graphql (2.3.15) lib/graphql/schema/resolver.rb:108:in `block (3 levels) in resolve_with_support'
graphql (2.3.15) lib/graphql/schema.rb:1413:in `after_lazy'
graphql (2.3.15) lib/graphql/query.rb:393:in `after_lazy'
graphql (2.3.15) lib/graphql/schema/resolver.rb:96:in `block (2 levels) in resolve_with_support'
graphql (2.3.15) lib/graphql/schema.rb:1413:in `after_lazy'
graphql (2.3.15) lib/graphql/query.rb:393:in `after_lazy'
graphql (2.3.15) lib/graphql/schema/resolver.rb:87:in `block in resolve_with_support'
graphql (2.3.15) lib/graphql/schema.rb:1413:in `after_lazy'
graphql (2.3.15) lib/graphql/query.rb:393:in `after_lazy'
graphql (2.3.15) lib/graphql/schema/resolver.rb:75:in `resolve_with_support'
graphql (2.3.15) lib/graphql/schema/has_single_input_argument.rb:36:in `resolve_with_support'
graphql (2.3.15) lib/graphql/schema/relay_classic_mutation.rb:45:in `resolve_with_support'
graphql (2.3.15) lib/graphql/schema/field.rb:735:in `public_send'
graphql (2.3.15) lib/graphql/schema/field.rb:735:in `block (2 levels) in resolve'
graphql (2.3.15) lib/graphql/schema/field.rb:880:in `block in with_extensions'
graphql (2.3.15) lib/graphql/schema/field.rb:916:in `block (2 levels) in run_extensions_before_resolve'
graphql (2.3.15) lib/graphql/schema/field.rb:916:in `block (2 levels) in run_extensions_before_resolve'
graphql (2.3.15) lib/graphql/schema/field.rb:919:in `run_extensions_before_resolve'
graphql (2.3.15) lib/graphql/schema/field.rb:916:in `block in run_extensions_before_resolve'
graphql (2.3.15) lib/graphql/schema/field_extension.rb:134:in `resolve'
graphql (2.3.15) lib/graphql/schema/field.rb:903:in `run_extensions_before_resolve'
graphql (2.3.15) lib/graphql/schema/field.rb:916:in `block in run_extensions_before_resolve'
lib/gitlab/graphql/present/field_extension.rb:18:in `resolve'
graphql (2.3.15) lib/graphql/schema/field.rb:903:in `run_extensions_before_resolve'
graphql (2.3.15) lib/graphql/schema/field.rb:875:in `with_extensions'
graphql (2.3.15) lib/graphql/schema/field.rb:706:in `block in resolve'
graphql (2.3.15) lib/graphql/schema.rb:1413:in `after_lazy'
graphql (2.3.15) lib/graphql/query.rb:393:in `after_lazy'
graphql (2.3.15) lib/graphql/schema/field.rb:704:in `resolve'
graphql (2.3.15) lib/graphql/execution/interpreter/runtime.rb:375:in `block (2 levels) in evaluate_selection_with_resolved_keyword_args'
graphql (2.3.15) lib/graphql/tracing/trace.rb:52:in `execute_field'
batch-loader (2.0.5) lib/batch_loader/graphql.rb:7:in `execute_field'
graphql (2.3.15) lib/graphql/schema/timeout.rb:84:in `execute_field'
...