-
-
Notifications
You must be signed in to change notification settings - Fork 103
Description
ToDo
- Make code consistent in what boolean values to accept
- Agree/Decide/Define what the standard boolean value formats are
- Document the standard boolean value format
Claude Code Analysis
Claude Code Prompt (on plone.restapi checkout):
analyse the code base of plone.restapi which url parameters are used for
boolean values (e.g. True, False, true, false, yes, no, 0, 1).
⏺ I'll analyze the plone.restapi codebase to identify how boolean URL
parameters are handled and what formats are accepted.
⏺ Explore(Analyze boolean URL parameters)
⎿ Done (36 tool uses · 71.4k tokens · 1m 46s)
⏺ I've completed a comprehensive analysis of boolean URL parameter handling
in the plone.restapi codebase. Here are the key findings:
Main Boolean Conversion Function
The primary function is boolean_value() located in
src/plone/restapi/deserializer/init.py:20-31:
def boolean_value(value):
return value not in {False, "false", "False", "0", 0}
This uses a blacklist approach - only these specific values return False:
- False (boolean)
- "false" (lowercase string)
- "False" (uppercase string)
- "0" (string)
- 0 (integer)
Everything else returns True, including: True, "true", "True", "1", 1, or
even "yes", "no", "foobar".
URL Parameters Using Boolean Values
- include_items (Folders & Collections)
- Files: src/plone/restapi/serializer/dxcontent.py:176,
src/plone/restapi/serializer/collection.py:19 - Uses: boolean_value() function
- Example: GET /folder?include_items=false excludes children items
- fullobjects (Search)
- File: src/plone/restapi/search/handler.py:78
- Uses: Presence check (if key exists in query)
- Example: GET /@search?fullobjects=1 returns full objects
- use_site_search_settings (Search)
- File: src/plone/restapi/search/handler.py:86
- Uses: Presence check (if key exists in query)
- Example: GET /@search?use_site_search_settings=1 applies Plone search
settings
Special Case: Boolean Index Queries
For catalog boolean index queries, there's a more restrictive parser in
src/plone/restapi/search/query.py:219-230:
Only accepts (case-sensitive, lowercase only):
- "true" or "1" → True
- "false" or "0" → False
Any other format raises a QueryParsingError.
Key Inconsistency
There are two different approaches in the codebase:
- boolean_value(): Permissive blacklist - accepts "True", "False",
"true", "false", "0", "1" - BooleanIndexQueryParser: Restrictive whitelist - only accepts lowercase
"true", "false", "0", "1"
Recommendation
For consistent API usage, the safest formats are:
- true or 1 for true values
- false or 0 for false values
These work across all boolean parameter types in the codebase.