Skip to content

fix: allow creating project variables without variableId (#11765)#11823

Open
aakarsh12x wants to merge 1 commit intoappwrite:1.9.xfrom
aakarsh12x:fix/11765-global-variables
Open

fix: allow creating project variables without variableId (#11765)#11823
aakarsh12x wants to merge 1 commit intoappwrite:1.9.xfrom
aakarsh12x:fix/11765-global-variables

Conversation

@aakarsh12x
Copy link
Copy Markdown

Summary

This fixes project global variable creation in local 1.9.0 setups when the request omits �ariableId.

What was broken

Creating a global variable from the Console could fail with:

Param "variableId" is not optional.

Root cause

src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php still treated �ariableId as a required request parameter, even though the endpoint already supports unique() IDs internally and older compatibility filters already backfill the same default.

Functions and Sites already generate variable IDs server-side, but Project variables still required the client to send one. That made the project/global variables flow inconsistent and caused the request to fail before the existing unique() handling could run.

Fix

  • make �ariableId optional for project variable creation
  • default it to unique() at the request parameter level
  • keep the existing server-side unique() to ID::unique() conversion unchanged
  • add a regression test that creates a project variable without sending �ariableId

Validation

  • Added an e2e regression in ProjectsConsoleClientTest that exercises POST /project/variables without �ariableId
  • I could not execute the PHP/e2e suite in this environment because PHP is not installed locally and the Docker Desktop daemon is unavailable from this shell

Fixes #11765

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 8, 2026

Greptile Summary

This PR fixes a regression in project (global) variable creation where omitting variableId in the request body caused a "Param variableId is not optional" error. The fix makes variableId optional with a default of 'unique()', matching the behaviour already present in Functions and Sites variable endpoints. The existing server-side unique()ID::unique() conversion on line 75 of Create.php remains untouched and handles the default correctly.

  • Create.php: variableId param changed from required to optional (true), with a default of 'unique()' and the existing lazy-injection of dbForProject for the CustomId validator — no other logic changed.
  • ProjectsConsoleClientTest.php: The first success case in testCreateProjectVariable now omits variableId entirely, serving as a regression guard; remaining cases still explicitly send 'unique()' which exercises the existing conversion path.
  • Minor: the new omit-ID test case does not assert that the auto-generated $id in the response is non-empty.

Confidence Score: 5/5

Safe to merge — the change is a minimal, targeted fix with no logic regressions and only a minor test improvement remaining.

Both changed files are straightforward: one parameter is made optional with a sensible default, and a regression test is added. The only remaining finding is a P2 style suggestion (missing assertNotEmpty on the auto-generated ID in the new test case), which does not affect correctness or production behaviour.

No files require special attention.

Vulnerabilities

No security concerns identified. The change only makes an ID parameter optional (defaulting to a server-generated unique value) and adds a test; no new input surfaces, privilege changes, or data-exposure paths are introduced.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php Makes variableId optional with a default of 'unique()', consistent with how the rest of the variable creation endpoints work; logic is sound and the existing unique()ID::unique() conversion on line 75 handles it correctly.
tests/e2e/Services/Projects/ProjectsConsoleClientTest.php First success case in testCreateProjectVariable now omits variableId to exercise the regression path; existing failure cases still pass 'unique()' explicitly which is fine. Minor: the omit-ID case doesn't assert the returned $id is non-empty.

Comments Outside Diff (1)

  1. tests/e2e/Services/Projects/ProjectsConsoleClientTest.php, line 4752-4755 (link)

    P2 Missing auto-generated ID assertion

    The new regression case that omits variableId verifies the HTTP status code and payload fields, but never confirms that the server actually returned a non-empty $id. Since the whole point of the fix is that the server must auto-generate a valid ID, it would be worth asserting that here:

Reviews (1): Last reviewed commit: "fix: allow creating project variables wi..." | Re-trigger Greptile

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.

Global variables not working in 1.9.0 local

1 participant