gitbutlerapp/gitbutler · error

GitHub GraphQL convertPullRequestToDraft returned an empty…

Error message

GitHub GraphQL convertPullRequestToDraft returned an empty pull request id

What it means

The convertPullRequestToDraft GraphQL mutation returned successfully but with an empty pull_request.id in the response. The library requires the node id to consider the operation confirmed and bails otherwise.

Solutions

  1. Skip the call when the PR is already a draft (check state == 'draft' beforehand)
  2. Inspect the raw GraphQL response to confirm whether the id is truly absent
  3. Confirm the authenticated token has write access to the repository
  4. Check the GitHub GraphQL schema/changelog for renames affecting the queried fields

Example fix

// before
client.set_pull_request_draft_state(&params).await?;
// after
if pr.is_draft {
    return Ok(()); // already a draft, nothing to do
}
client.set_pull_request_draft_state(&params).await?;
Defensive patterns

Strategy: validation

Validate before calling

// skip when already a draft
if pr.is_draft { return Ok(()); }

Try / catch

match client.set_pull_request_draft_state(&params).await {
    Err(e) if e.to_string().contains("empty pull request id") => {
        // refetch and verify whether the conversion actually happened
        let pr = client.get_pull_request(owner, repo, pr_number).await?;
        if pr.is_draft { Ok(()) } else { Err(e) }
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling set_pull_request_to_draft / convert_pull_request_to_draft when the mutation response lacks the PR node id — often because the PR is already a draft (no-op) or the GraphQL response shape is not what the client's query expects.

Common situations: Automations converting already-draft PRs; head branches from forks with restricted permissions; GitHub GraphQL schema changes.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/d9828cedaa2cd955. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-github/src/client.rs:1595

            pull_request: GraphQlPullRequest,
        }

        #[derive(Deserialize)]
        struct GraphQlPullRequest {
            id: String,
        }

        let data: MutationData = self
            .graphql_query(GQL_SET_PR_DRAFT, &Variables { pull_request_id })
            .await?;

        if data
            .convert_pull_request_to_draft
            .pull_request
            .id
            .is_empty()
        {
            bail!("GitHub GraphQL convertPullRequestToDraft returned an empty pull request id");
        }

        Ok(())
    }

    /// Enable or disable a PR's auto-merge.
    pub async fn set_pull_request_auto_merge(
        &self,
        params: &SetPullRequestAutoMergeParams<'_>,
    ) -> Result<()> {
        let pull_request_id = self
            .get_pull_request_node_id(params.owner, params.repo, params.pr_number)
            .await?;

        match &params.state {
            AutoMergeState::Disabled => {
                self.disable_auto_merge_pull_request(&pull_request_id).await
            }

View on GitHub (pinned to 58e5313667)