8000 Fix request filters with multi-method routes by abnegate · Pull Request #9743 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix request filters with multi-method routes #9743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 12, 2025
Merged

Fix request filters with multi-method routes #9743

merged 4 commits into from
May 12, 2025

Conversation

abnegate
Copy link
Member
@abnegate abnegate commented May 12, 2025

What does this PR do?

The request getParams method was updated to handle request filters when multiple methods are present on a single route, but the implementation did not merge/check parameters correctly, so if a request filter was run, only the explicit parameters defined on last method in the list were sent to the route.

This meant that when calling createDocument from a version lower than 1.6.0, the createDocuments params were used, so documentId and data were being stripped out. This lead to valid requests returning "The document data is missing. Try again with document data populated".

Test Plan

Updated existing tests + manual tests.

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?

Summary by CodeRabbit

  • Bug Fixes
    • Improved parameter handling for requests with multiple possible method definitions, ensuring that only parameters matching the correct method are returned.
  • Tests
    • Added comprehensive tests to verify correct parameter matching and filtering when multiple methods are associated with a route.

Copy link
coderabbitai bot commented May 12, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The getParams() method in the Request class was refactored to streamline the logic for filtering request parameters according to SDK method definitions associated with routes. Additionally, the test suite was expanded with new methods to verify correct parameter matching and filtering when multiple SDK methods are present on a route.

Changes

File(s) Change Summary
src/Appwrite/Utopia/Request.php Refactored getParams() to simplify logic: matches parameters to a single SDK method, filters accordingly, and applies filters.
tests/unit/Utopia/RequestTest.php Added multiple test methods and a helper to verify getParams() behavior with routes having multiple SDK methods.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Request
    participant Route
    participant SDKMethod
    participant Filter

    Client->>Request: Send request with parameters
    Request->>Route: Retrieve SDK methods for current route
    Route-->>Request: Return list of SDK methods
    loop For each SDK method
        Request->>SDKMethod: Compare parameter keys with method's parameters
    end
    alt Matching method found
        Request->>Request: Filter parameters by method's definition
        loop For each filter
            Request->>Filter: Apply filter.parse(endpoint, param)
        end
        Request-->>Client: Return filtered parameters
    else No matching method
        Request-->>Client: Return raw parameters
    end
Loading

Poem

In tangled code where methods dwell,
A rabbit hopped and cleaned the shell.
Now parameters match just right,
With tests to check them day and night.
No more confusion, filters flow—
The logic’s clear, the tests all go!
🐰✨


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@abnegate
Copy link
Member Author

@coderabbitai full review

Copy link
coderabbitai bot commented May 12, 2025
✅ Actions performed

Full review triggered.

Copy link
github-actions bot commented May 12, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
@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: 2

🧹 Nitpick comments (4)
src/Appwrite/Utopia/Request.php (3)

62-70: Filtering block can be simplified & made safer

array_intersect_key() plus array_flip() is correct but a bit heavy; additionally, $parameters isn’t re-indexed, which may surpris 8000 e consumers expecting consecutive numeric keys for lists. A clearer and slightly faster alternative:

-    $parameters = \array_intersect_key($parameters, \array_flip($definedNames));
+    $parameters = \array_filter(
+        $parameters,
+        fn($key) => \in_array($key, $definedNames, true),
+        ARRAY_FILTER_USE_KEY
+    );

Minor, but improves readability and avoids the temporary flipped array.


73-76: Potential performance hit from reassigning $parameters in every loop

parse() already returns the transformed array; however, if many filters are chained the whole parameter array is re-allocated each time.
If filters are numerous or the array is large, consider streaming or at least cloning only when the filter actually mutates data (many implementations might be no-ops).

Not urgent, but worth profiling.


1-223: Fix style issue flagged by Pint

CI reports a Pint failure for a “function declaration” style problem.
Run vendor/bin/pint or composer pint locally and commit the auto-generated diff to keep the pipeline green.

🧰 Tools
🪛 GitHub Actions: Linter

[error] 1-1: PHP CS Fixer (Pint) style check failed: 1 style issue detected related to function declaration. Run 'vendor/bin/pint' to fix code style issues.

tests/unit/Utopia/RequestTest.php (1)

150-186: Helper builds Parameter objects without specifying optionality flag name

new Parameter('bar', optional: true) relies on a named parameter optional, which is great for clarity.
Consider also setting type or description if those fields exist in Parameter for richer tests, and add a comment noting which param is required vs optional to ease future maintenance.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de7c8b8 and 3203ea5.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • src/Appwrite/Utopia/Request.php (2 hunks)
  • tests/unit/Utopia/RequestTest.php (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: Linter
src/Appwrite/Utopia/Request.php

[error] 1-1: PHP CS Fixer (Pint) style check failed: 1 style issue detected related to function declaration. Run 'vendor/bin/pint' to fix code style issues.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Setup & Build Appwrite Image
🔇 Additional comments (1)
tests/unit/Utopia/RequestTest.php (1)

96-112: Unit test legitimises behaviour that conflicts with SDK contract

testGetParamsWithAllOptional() passes only the optional bar param while omitting required foo, yet expects the call to be accepted.
After tightening required-parameter checks (see code review above) this test will fail – and should fail.

Please reassess the intended contract: if foo is mandatory, the test should assert a fallback or an exception, not a silent match.

If foo is not mandatory, mark it accordingly in setupMultiMethodRoute() by setting optional: true.

Copy link
github-actions bot commented May 12, 2025

✨ Benchmark results

  • Requests per second: 1,112
  • Requests with 200 status code: 200,223
  • P99 latency: 0.163555602

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,112 1,380
200 200,223 248,528
P99 0.163555602 0.133258129

@Meldiron
Copy link
Contributor

Validated on stage - reproduced issue first, then deployed, then made sure issue is nomore.

Merging now

@Meldiron Meldiron merged commit 1276e74 into 1.6.x May 12, 2025
31 checks passed
@christyjacob4 christyjacob4 deleted the fix-filters branch May 12, 2025 08:33
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.

2 participants
0