Skip to content

fix: strip whitespace and handle null values in instance configuration#9239

Open
okxint wants to merge 1 commit into
makeplane:previewfrom
okxint:fix/strip-whitespace-instance-config
Open

fix: strip whitespace and handle null values in instance configuration#9239
okxint wants to merge 1 commit into
makeplane:previewfrom
okxint:fix/strip-whitespace-instance-config

Conversation

@okxint

@okxint okxint commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What

The instance configuration PATCH endpoint stored raw values from request.data without sanitization, causing two issues:

  1. Null valuesstr(None) produces the literal string "None" instead of an empty string, so clearing a field would store "None" in the DB.
  2. Whitespace — values with leading/trailing spaces (e.g. copy-pasted URLs or tokens) were stored as-is, which can silently break downstream usage.

Fix

raw_value = request.data.get(configuration.key, configuration.value)
value = "" if raw_value is None else str(raw_value).strip()

Both issues are addressed in a single sanitization step before the value is encrypted or stored.

Files changed

  • apps/api/plane/license/api/views/configuration.py

Summary by CodeRabbit

  • Bug Fixes
    • Fixed configuration value normalization to properly handle null values and trim excess whitespace in API requests.

When patching instance configuration values, the raw values from
request.data were used directly without sanitization. This adds:
- Whitespace stripping via str().strip() to prevent leading/trailing
  spaces from being stored
- Explicit None handling so that null values become empty strings
  instead of the literal string "None"
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

In InstanceConfigurationEndpoint.patch, the value lookup for each configuration key is replaced with a two-step normalization: raw_value is read from request.data, then value is set to "" if raw_value is None, or str(raw_value).strip() otherwise.

Changes

Configuration Value Normalization

Layer / File(s) Summary
Value sanitization in InstanceConfigurationEndpoint.patch
apps/api/plane/license/api/views/configuration.py
Replaces direct request.data.get(configuration.key, configuration.value) with a raw_value extraction followed by None"" coercion and .strip() on non-None values before the value is encrypted or stored.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hops through config land,
Trimming spaces with a careful hand.
None becomes "" — no fuss, no fright,
Whitespace stripped and values right.
🐇 Clean configs, day and night!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: fixing whitespace stripping and null value handling in instance configuration, which directly matches the patch logic modifications.
Description check ✅ Passed The PR description provides comprehensive detail on the problem, solution, and affected files. However, it lacks several template sections: Type of Change, Test Scenarios, Screenshots, and References.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/api/plane/license/api/views/configuration.py`:
- Around line 48-49: In the configuration sanitization logic where raw_value is
converted to a string using str(), add explicit handling for boolean values.
After the existing line that strips the string value, check if raw_value is a
boolean type using isinstance() and convert it to "1" for True or "0" for False
to match the expected string format throughout the codebase. This ensures that
boolean flag configurations like EMAIL_USE_TLS and EMAIL_USE_SSL are properly
converted to the string representations they are compared against in equality
checks, preventing failed validations when the frontend sends actual boolean
types.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0a0ab350-19e8-4ada-8b2a-e46fdffada78

📥 Commits

Reviewing files that changed from the base of the PR and between f2feca6 and 79b7306.

📒 Files selected for processing (1)
  • apps/api/plane/license/api/views/configuration.py

Comment on lines +48 to +49
raw_value = request.data.get(configuration.key, configuration.value)
value = "" if raw_value is None else str(raw_value).strip()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for configuration keys that are compared to "0" or "1" strings
rg -n -C2 'EMAIL_USE_TLS|EMAIL_USE_SSL|ENABLE_SMTP' --type=py

# Search for any validation or serializer logic for InstanceConfiguration
ast-grep --pattern 'class InstanceConfigurationSerializer($$$) {
  $$$
}'

# Check if request.data typing or validation constrains boolean flags
rg -n 'InstanceConfiguration.*patch|def patch.*InstanceConfiguration' --type=py -A 10

Repository: makeplane/plane

Length of output: 17116


🏁 Script executed:

# Read the configuration.py file to see the full patch method context
cat -n apps/api/plane/license/api/views/configuration.py | head -60

Repository: makeplane/plane

Length of output: 2836


🏁 Script executed:

# Search for InstanceConfiguration model definition
rg -n 'class InstanceConfiguration' --type=py -A 10

Repository: makeplane/plane

Length of output: 3171


🏁 Script executed:

# Search for any serializer related to InstanceConfiguration
rg -n 'InstanceConfiguration.*Serializer|class.*Serializer.*InstanceConfiguration' --type=py -A 15

Repository: makeplane/plane

Length of output: 5740


🏁 Script executed:

# Check if there's any type conversion or validation for boolean fields
rg -n 'BooleanField|to_internal_value|validate' apps/api/plane/license/api/ --type=py | head -20

Repository: makeplane/plane

Length of output: 1715


🏁 Script executed:

# Check if there are any tests or examples showing what format is sent to the patch endpoint
rg -n 'EMAIL_USE_TLS|EMAIL_USE_SSL|ENABLE_SMTP' apps/api/plane/license/api/tests/ --type=py -A 2 -B 2 2>/dev/null || echo "No tests found"

Repository: makeplane/plane

Length of output: 74


🏁 Script executed:

# Check frontend/migrations to see if booleans might be sent
fd -e ts -e tsx -e js apps/web 2>/dev/null | head -5

Repository: makeplane/plane

Length of output: 41


Handle boolean-to-string conversion for flag-type configurations.

The str() coercion on line 49 converts boolean True/False to strings "True"/"False", but boolean flag configurations like EMAIL_USE_TLS and EMAIL_USE_SSL are compared as "1" or "0" strings throughout the codebase (e.g., use_tls=EMAIL_USE_TLS == "1"). If the frontend sends actual boolean types for these flags, the sanitization produces incorrect string values that fail equality checks.

The InstanceConfigurationSerializer has no custom field definitions or type validation (fields = "__all__"), so booleans pass through unchecked. Add explicit handling to convert boolean values to the expected string format:

value = "" if raw_value is None else str(raw_value).strip()
# For boolean flags, convert to "1" or "0"
if isinstance(raw_value, bool):
    value = "1" if raw_value else "0"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/api/plane/license/api/views/configuration.py` around lines 48 - 49, In
the configuration sanitization logic where raw_value is converted to a string
using str(), add explicit handling for boolean values. After the existing line
that strips the string value, check if raw_value is a boolean type using
isinstance() and convert it to "1" for True or "0" for False to match the
expected string format throughout the codebase. This ensures that boolean flag
configurations like EMAIL_USE_TLS and EMAIL_USE_SSL are properly converted to
the string representations they are compared against in equality checks,
preventing failed validations when the frontend sends actual boolean types.

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.

1 participant