fix(destination): skip project variables with unusable keys - #218
Merged
Conversation
Project variables are written straight into the variables collection here, which bypasses the API's validation of the key. The API only accepts keys that are valid environment variable names, since that is what they become at build and runtime, so an import can still store a key that fails at build time and cannot be fixed through the API afterwards. A source project can hold such a key when it was stored before the rule existed. Check the key before creating the document and skip the resource with a reason, matching how a duplicate key is already reported, so one bad key does not abort the import. Server-side rule: appwrite/appwrite#13181 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
Greptile SummaryThe PR prevents project variables with keys that cannot be used as environment-variable names from being written directly into Appwrite’s variables collection.
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable issue identified. The validation operates on a guaranteed string, rejects malformed or oversized keys before any database access, and the existing import flow preserves and reports the skipped status while continuing the migration. Important Files Changed
Reviews (1): Last reviewed commit: "fix(destination): skip project variables..." | Re-trigger Greptile |
ChiragAgg5k
approved these changes
Aug 12, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Validates a project variable's key before writing it into the
variablescollection, and skips the resource with a reason when it cannot be used.Why
createProjectVariablewrites to the collection directly withcreateDocument, which bypasses the API's validation of the key. appwrite/appwrite#13181 makes the API reject keys that are not valid environment variable names (^[A-Za-z_]\w*$, max 255) — they become environment variable names at build and runtime, so anything else fails when the build environment is assembled.That leaves this as the one remaining supported path that can still store an unusable key. A source project can hold one when it was stored before the rule existed, and once imported it fails at build time and can no longer be corrected through the API.
Changes
VARIABLE_KEY_PATTERNconstant alongside the existing class constants.createProjectVariablechecks length and shape first and setsSTATUS_SKIPPEDwith a reason, mirroring how an already-existing key is reported, so one bad key does not abort the whole import.$keyand reused by the existing duplicate lookup.No new dependency: the check is a
preg_matchagainst the pattern plusUtopiaDatabase::LENGTH_KEY, rather than pulling inutopia-php/validatorsfor a single rule.ProjectVariableis the only variable resource in the library, so this covers the full surface.Testing
Verified with
php -lonly.composer installfails here with "Could not authenticate against github.com", and this machine runs PHP 8.4 against the package's>=8.5requirement, so the suite could not be installed or run locally — CI will be the first real run.A test belongs here and I did not want to guess at it blind:
tests/Migration/Unit/Destinations/AppwriteDatabaseStatusTest.phphas an in-memory harness (MemoryAdapter + MockSource + a real transfer) that acreateProjectVariablecase should mirror — asserting an invalid key is skipped, no document is written, and a valid key alongside it still lands. Happy to add it if you'd prefer it in this PR.