Skip to content

Conversation

@ChiragAgg5k
Copy link
Member

@ChiragAgg5k ChiragAgg5k commented Nov 4, 2025

Screenshot 2025-11-04 at 2 03 12 PM

Summary by CodeRabbit

  • Improvements
    • Added safer formatting for multipart form-data values (e.g., boolean coercion) to produced Python code.
    • Unified handling of body and form-data parameters when building request payloads.
    • Strengthened conditional logic to avoid assigning invalid None values for optional/non-nullable parameters.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 4, 2025

Walkthrough

A new Twig filter formatParamValue was added to Appwrite\SDK\Language\Python (within getFilters()), providing conditional formatting for parameter values when handling multipart/form-data (notably converting boolean values to lowercase strings when appropriate). The Python params template (templates/python/base/params.twig) was refactored to merge body and formData parameter handling into a single loop, introduce paramName, isMultipart, and formattedValue helpers, and add conditional assignments for non-nullable, non-required parameters so api_params entries are only set when the value is not None.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • src/SDK/Language/Python.php: verify the new formatParamValue filter implementation and parameter ordering/typing.
  • templates/python/base/params.twig: review the merged body+formData loop, conditional guards for non-nullable/non-required params, and ensure behavior matches previous separate paths.
  • Attention areas:
    • Confirm boolean formatting only applies in the intended multipart/form-data cases and does not affect other types.
    • Ensure no duplicate or omitted parameters result from merging method.parameters.body and method.parameters.formData.
    • Validate the None-check logic for non-nullable, non-required parameters to avoid changing when keys are included in api_params.

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly and concisely describes the main change: preventing None values from being passed to non-nullable parameters in Python code generation.
✨ 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-passing-none-values-python

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9cab054 and 530ca3b.

📒 Files selected for processing (2)
  • src/SDK/Language/Python.php (1 hunks)
  • templates/python/base/params.twig (1 hunks)
⏰ 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). (19)
  • GitHub Check: swift (server)
  • GitHub Check: build (8.3, Python39)
  • GitHub Check: apple (client)
  • GitHub Check: build (8.3, Ruby30)
  • GitHub Check: flutter (client)
  • GitHub Check: build (8.3, Python311)
  • GitHub Check: build (8.3, KotlinJava17)
  • GitHub Check: build (8.3, Python312)
  • GitHub Check: build (8.3, AppleSwift56)
  • GitHub Check: android (client)
  • GitHub Check: build (8.3, Ruby27)
  • GitHub Check: build (8.3, FlutterBeta)
  • GitHub Check: build (8.3, KotlinJava8)
  • GitHub Check: build (8.3, Node20)
  • GitHub Check: build (8.3, DotNet80)
  • GitHub Check: build (8.3, Android14Java17)
  • GitHub Check: build (8.3, KotlinJava11)
  • GitHub Check: build (8.3, Android5Java17)
  • GitHub Check: build (8.3, FlutterStable)

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.

@ChiragAgg5k ChiragAgg5k closed this Nov 4, 2025
@ChiragAgg5k ChiragAgg5k force-pushed the fix-passing-none-values-python branch from e1af9f4 to 42df221 Compare November 4, 2025 08:31
@ChiragAgg5k ChiragAgg5k reopened this Nov 4, 2025
@ChiragAgg5k ChiragAgg5k force-pushed the fix-passing-none-values-python branch from fcc7179 to 9cab054 Compare November 4, 2025 08:37
Copy link
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

🧹 Nitpick comments (1)
templates/python/base/params.twig (1)

24-24: Add defensive check for empty consumes array.

Accessing method.consumes[0] without verifying the array is non-empty could cause a template error if a method has no content-type specified.

Apply this diff to add a safety check:

-{% set isMultipart = method.consumes[0] == "multipart/form-data" %}
+{% set isMultipart = method.consumes|length > 0 and method.consumes[0] == "multipart/form-data" %}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42df221 and fcc7179.

📒 Files selected for processing (3)
  • src/SDK/Language/Python.php (1 hunks)
  • templates/php/docs/service.md.twig (0 hunks)
  • templates/python/base/params.twig (1 hunks)
💤 Files with no reviewable changes (1)
  • templates/php/docs/service.md.twig
⏰ 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). (14)
  • GitHub Check: web (client)
  • GitHub Check: dart (server)
  • GitHub Check: apple (client)
  • GitHub Check: node (server)
  • GitHub Check: kotlin (server)
  • GitHub Check: android (client)
  • GitHub Check: build (8.3, Python310)
  • GitHub Check: build (8.3, Go118)
  • GitHub Check: build (8.3, FlutterStable)
  • GitHub Check: build (8.3, CLINode18)
  • GitHub Check: build (8.3, DotNet80)
  • GitHub Check: build (8.3, CLINode16)
  • GitHub Check: build (8.3, DartBeta)
  • GitHub Check: build (8.3, Android5Java17)
🔇 Additional comments (3)
templates/python/base/params.twig (2)

15-20: Good addition to prevent None values for non-nullable parameters.

The conditional logic correctly ensures that optional non-nullable query parameters are only included when they have a value, preventing None from being passed to endpoints that don't accept null values.


22-32: Unified body parameter handling looks good.

The refactored body parameter handling successfully applies the same None-skipping logic as query parameters, ensuring consistency across the codebase. The integration with formatParamValue properly handles multipart form data formatting while preserving the None-check behavior for optional non-nullable parameters.

src/SDK/Language/Python.php (1)

402-407: Consider handling additional types for multipart form data.

The filter currently only converts booleans to lowercase strings, leaving integers, floats, and other types unchanged. In multipart/form-data requests, most HTTP libraries expect all field values to be strings. Consider whether numeric types should also be explicitly converted to strings.

Additionally, when a nullable parameter has a None value, the generated expression str(None).lower() if type(None) is bool else None will evaluate to None, which may then be serialized as the string "None" by the HTTP library rather than being omitted. Verify whether this behavior aligns with the API's expectations for nullable parameters.

Copy link
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: 1

🧹 Nitpick comments (1)
src/SDK/Language/Python.php (1)

402-407: Consider using class constants for type comparisons.

The filter uses string literals 'string' and 'array' for type checking, but the class defines constants like self::TYPE_STRING and self::TYPE_ARRAY. For consistency and maintainability, consider using these constants instead.

Apply this diff:

-            new TwigFilter('formatParamValue', function (string $paramName, string $paramType, bool $isMultipartFormData) {
-                if ($isMultipartFormData && $paramType !== 'string' && $paramType !== 'array') {
+            new TwigFilter('formatParamValue', function (string $paramName, string $paramType, bool $isMultipartFormData) {
+                if ($isMultipartFormData && $paramType !== self::TYPE_STRING && $paramType !== self::TYPE_ARRAY) {
                     return "str({$paramName}).lower() if type({$paramName}) is bool else {$paramName}";
                 }
                 return $paramName;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fcc7179 and 9cab054.

📒 Files selected for processing (2)
  • src/SDK/Language/Python.php (1 hunks)
  • templates/python/base/params.twig (1 hunks)
⏰ 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). (3)
  • GitHub Check: build (8.3, KotlinJava17)
  • GitHub Check: build (8.3, KotlinJava8)
  • GitHub Check: build (8.3, KotlinJava11)
🔇 Additional comments (2)
templates/python/base/params.twig (2)

15-20: Good implementation of None-checking for query parameters.

The conditional logic correctly skips adding query parameters to the API params dictionary when they are non-nullable, non-required, and have a None value. This aligns with the PR objective.


26-31: Correct implementation of None-checking for body/formData parameters.

The conditional logic properly handles non-nullable, non-required parameters by checking for None before adding them to api_params. The use of formattedValue ensures proper formatting for multipart form data scenarios. This successfully achieves the PR objective.

@ChiragAgg5k ChiragAgg5k force-pushed the fix-passing-none-values-python branch from 9cab054 to 7a8cdde Compare November 4, 2025 08:47
@abnegate abnegate merged commit cd71267 into master Nov 4, 2025
52 checks passed
@abnegate abnegate deleted the fix-passing-none-values-python branch November 4, 2025 09:55
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