Skip to content

Fix entrypoint#10979

Merged
loks0n merged 1 commit into1.8.xfrom
fix-credentials
Dec 17, 2025
Merged

Fix entrypoint#10979
loks0n merged 1 commit into1.8.xfrom
fix-credentials

Conversation

@fogelito
Copy link
Copy Markdown
Contributor

What does this PR do?

(Provide a description of what this PR does and why it's needed.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)

Related PRs and Issues

  • (Related PR or issue)

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 17, 2025

📝 Walkthrough

Walkthrough

The migration worker refactors endpoint normalization logic within a single PHP file. Runtime endpoint normalization that previously mapped localhost/v1 to the platform hostname with protocol in processSource was removed. This logic was relocated to processMigration, where it now assigns the normalized endpoint to credentials['endpoint'] when credentials exist but the endpoint is empty. A clarifying comment was added to document the change.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10-15 minutes

  • Verify the endpoint normalization logic functions correctly in its new location within processMigration
  • Ensure all existing code paths that relied on processSource normalization still operate as expected
  • Validate that the credentials['endpoint'] assignment handles all anticipated scenarios with the protocol/hostname logic

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description consists entirely of the contribution template with all placeholder sections empty. No actual details about the changes, motivation, test plan, or related issues are provided. Replace the template with concrete details: explain why the endpoint normalization was moved, how it was tested, and reference any related issues or PRs.
Title check ❓ Inconclusive The title is too vague and generic. While 'Fix entrypoint' relates to the code changes, it lacks specificity about what entrypoint issue was fixed and why. Provide a more descriptive title that explains what specific entrypoint issue was fixed, such as 'Fix endpoint normalization in migration credentials' or 'Move endpoint assignment to processMigration.'
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-credentials

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
libpng 1.6.51-r0 CVE-2025-66293 HIGH
libpng-dev 1.6.51-r0 CVE-2025-66293 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Appwrite/Platform/Workers/Migrations.php (1)

320-336: Critical logic error: condition prevents endpoint normalization when credentials exist.

Line 322 checks empty($migration->getAttribute('credentials', [])), which means the block only executes when credentials are completely absent. If credentials exist but are incomplete (e.g., projectId and apiKey are present but endpoint is missing), the condition evaluates to false and the block never executes. This means the endpoint won't be normalized, and processSource at line 342 will fail when accessing $credentials['endpoint'].

This contradicts both the AI summary ("when credentials are present but endpoint is empty") and the PR intent to fix entrypoint issues.

Apply this diff to fix the logic:

         try {
             if (
                 $migration->getAttribute('source') === SourceAppwrite::getName() &&
-                empty($migration->getAttribute('credentials', []))
+                !empty($migration->getAttribute('credentials', []))
             ) {
                 $credentials = $migration->getAttribute('credentials', []);
                 $credentials['projectId'] = $credentials['projectId'] ?? $project->getId();
                 $credentials['apiKey'] = $credentials['apiKey'] ?? $tempAPIKey();
 
                 /**
                  * endpoint set
                  */
                 if (empty($credentials['endpoint'])) {
                     $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
                     $credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1';
                 }
                 $migration->setAttribute('credentials', $credentials);
             }

Alternatively, remove the empty() check entirely to handle both empty and incomplete credentials:

         try {
-            if (
-                $migration->getAttribute('source') === SourceAppwrite::getName() &&
-                empty($migration->getAttribute('credentials', []))
-            ) {
+            if ($migration->getAttribute('source') === SourceAppwrite::getName()) {
                 $credentials = $migration->getAttribute('credentials', []);
                 $credentials['projectId'] = $credentials['projectId'] ?? $project->getId();
                 $credentials['apiKey'] = $credentials['apiKey'] ?? $tempAPIKey;
 
                 /**
                  * endpoint set
                  */
                 if (empty($credentials['endpoint'])) {
                     $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
                     $credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1';
                 }
                 $migration->setAttribute('credentials', $credentials);
             }

The second approach is simpler and leverages the null coalescing operators to handle all cases properly.

🧹 Nitpick comments (1)
src/Appwrite/Platform/Workers/Migrations.php (1)

328-330: Improve comment to explain the WHY, not just the WHAT.

The comment "endpoint set" simply restates what the code does. A better comment would explain why this normalization is needed and when it applies.

Consider this more informative comment:

-                /**
-                 * endpoint set
-                 */
+                // Normalize endpoint to platform hostname when not explicitly provided
+                // This handles migrations where endpoint is empty or uses localhost
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5149346 and fcbb073.

📒 Files selected for processing (1)
  • src/Appwrite/Platform/Workers/Migrations.php (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ItzNotABug
Repo: appwrite/appwrite PR: 9661
File: docs/references/migrations/migration-csv.md:1-1
Timestamp: 2025-04-17T08:08:59.449Z
Learning: Documentation files in docs/references/migrations/ follow a minimalist pattern with 1-2 sentences describing the endpoint's functionality, without including detailed API specifications like HTTP methods, parameters, headers, or examples.
📚 Learning: 2025-10-23T08:06:38.889Z
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10546
File: src/Appwrite/Platform/Workers/Migrations.php:144-148
Timestamp: 2025-10-23T08:06:38.889Z
Learning: In the Appwrite codebase, migration workers receive already-validated data from queued jobs. Query validation using Query::parseQueries() happens at the API endpoint level (with try-catch for QueryException) before jobs are queued, so workers in src/Appwrite/Platform/Workers/Migrations.php don't need redundant validation.

Applied to files:

  • src/Appwrite/Platform/Workers/Migrations.php
📚 Learning: 2025-04-17T08:08:59.449Z
Learnt from: ItzNotABug
Repo: appwrite/appwrite PR: 9661
File: docs/references/migrations/migration-csv.md:1-1
Timestamp: 2025-04-17T08:08:59.449Z
Learning: Documentation files in docs/references/migrations/ follow a minimalist pattern with 1-2 sentences describing the endpoint's functionality, without including detailed API specifications like HTTP methods, parameters, headers, or examples.

Applied to files:

  • src/Appwrite/Platform/Workers/Migrations.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: moderate
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan

@github-actions
Copy link
Copy Markdown

✨ Benchmark results

  • Requests per second: 1,123
  • Requests with 200 status code: 202,116
  • P99 latency: 0.172607498

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,123 1,192
200 202,116 214,523
P99 0.172607498 0.173892672

@loks0n loks0n merged commit 22fba9d into 1.8.x Dec 17, 2025
44 checks passed
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.

3 participants