|
| 1 | +# Known Issues - Sendbird Platform SDK Python |
| 2 | + |
| 3 | +This document tracks known issues and bugs in the SDK that are reflected in failing tests. |
| 4 | + |
| 5 | +## Optional Fields Rejecting None Values |
| 6 | + |
| 7 | +**Status**: 🐛 Bug |
| 8 | +**Severity**: Medium |
| 9 | +**Affected Version**: 2.1.1 |
| 10 | + |
| 11 | +### Description |
| 12 | + |
| 13 | +Optional fields in model classes incorrectly reject `None` values. According to OpenAPI specification and general API best practices, optional fields should accept `None` values, but the current SDK implementation raises `ApiTypeError` when `None` is explicitly passed to optional fields. |
| 14 | + |
| 15 | +### Expected Behavior |
| 16 | + |
| 17 | +```python |
| 18 | +# This SHOULD work for optional fields |
| 19 | +model = CreateAUserRequest( |
| 20 | + nickname="John Doe", |
| 21 | + profile_url="https://example.com/profile.jpg", |
| 22 | + user_id="user123", |
| 23 | + discovery_keys=None, # Optional field - should accept None |
| 24 | + metadata=None # Optional field - should accept None |
| 25 | +) |
| 26 | +``` |
| 27 | + |
| 28 | +### Actual Behavior |
| 29 | + |
| 30 | +```python |
| 31 | +# This currently FAILS with ApiTypeError |
| 32 | +model = CreateAUserRequest( |
| 33 | + nickname="John Doe", |
| 34 | + profile_url="https://example.com/profile.jpg", |
| 35 | + user_id="user123", |
| 36 | + discovery_keys=None # ❌ Raises: Invalid type for variable 'discovery_keys' |
| 37 | +) |
| 38 | +``` |
| 39 | + |
| 40 | +### Workaround |
| 41 | + |
| 42 | +Instead of passing `None`, simply omit the field: |
| 43 | + |
| 44 | +```python |
| 45 | +# ✅ This works |
| 46 | +model = CreateAUserRequest( |
| 47 | + nickname="John Doe", |
| 48 | + profile_url="https://example.com/profile.jpg", |
| 49 | + user_id="user123" |
| 50 | + # discovery_keys and metadata omitted - works fine |
| 51 | +) |
| 52 | +``` |
| 53 | + |
| 54 | +Or use empty values: |
| 55 | + |
| 56 | +```python |
| 57 | +# ✅ This also works |
| 58 | +model = CreateAUserRequest( |
| 59 | + nickname="John Doe", |
| 60 | + profile_url="https://example.com/profile.jpg", |
| 61 | + user_id="user123", |
| 62 | + discovery_keys=[], # Empty list instead of None |
| 63 | + metadata={} # Empty dict instead of None |
| 64 | +) |
| 65 | +``` |
| 66 | + |
| 67 | +### Affected Models |
| 68 | + |
| 69 | +The following models have optional fields that incorrectly reject `None`: |
| 70 | + |
| 71 | +1. **AcceptAnInvitationRequest** |
| 72 | + - `access_code` (optional but not nullable) |
| 73 | + |
| 74 | +2. **CreateAUserRequest** |
| 75 | + - `discovery_keys` (optional but not nullable) |
| 76 | + - `metadata` (optional but not nullable) |
| 77 | + - `profile_file` (optional but not nullable) |
| 78 | + |
| 79 | +3. **SendbirdUser** |
| 80 | + - `nickname` (optional but not nullable) |
| 81 | + - `profile_url` (optional but not nullable) |
| 82 | + - `discovery_keys` (optional but not nullable) |
| 83 | + - `preferred_languages` (optional but not nullable) |
| 84 | + - `session_tokens` (optional but not nullable) |
| 85 | + - `metadata` (optional but not nullable) |
| 86 | + - **Exception**: `state` field IS nullable (correctly accepts None) |
| 87 | + |
| 88 | +### Failing Tests |
| 89 | + |
| 90 | +The following tests document this issue and currently fail: |
| 91 | + |
| 92 | +```bash |
| 93 | +# Run these tests to see the issue |
| 94 | +pytest test/test_accept_an_invitation_request.py::TestAcceptAnInvitationRequest::testAcceptAnInvitationRequestOptionalFieldShouldAcceptNone -v |
| 95 | +pytest test/test_create_a_user_request.py::TestCreateAUserRequest::testCreateAUserRequestOptionalDiscoveryKeys -v |
| 96 | +pytest test/test_create_a_user_request.py::TestCreateAUserRequest::testCreateAUserRequestOptionalMetadata -v |
| 97 | +pytest test/test_sendbird_user.py::TestSendbirdUser::testSendbirdUserOptionalFields -v |
| 98 | +``` |
| 99 | + |
| 100 | +Test results: |
| 101 | +``` |
| 102 | +FAILED test/test_accept_an_invitation_request.py - ApiTypeError: Invalid type for variable 'access_code' |
| 103 | +FAILED test/test_create_a_user_request.py (multiple) - ApiTypeError for optional fields |
| 104 | +FAILED test/test_sendbird_user.py (multiple) - ApiTypeError for optional fields |
| 105 | +
|
| 106 | +7 failed, 244 passed |
| 107 | +``` |
| 108 | + |
| 109 | +### Root Cause |
| 110 | + |
| 111 | +This issue likely stems from the OpenAPI Generator configuration or template. The generator is not properly marking optional fields as nullable in the generated Python code. |
| 112 | + |
| 113 | +In the model files, optional non-nullable fields are defined as: |
| 114 | +```python |
| 115 | +'discovery_keys': ([str],), # Should be ([str], none_type,) for nullable |
| 116 | +``` |
| 117 | + |
| 118 | +While properly nullable fields are defined as: |
| 119 | +```python |
| 120 | +'state': (str, none_type,), # ✅ Correctly includes none_type |
| 121 | +``` |
| 122 | + |
| 123 | +### Potential Solutions |
| 124 | + |
| 125 | +1. **Update OpenAPI Generator Templates** |
| 126 | + - Modify the Python generator template to mark optional fields as nullable |
| 127 | + - Location: `sendbird-platform-openapi/` generator configuration |
| 128 | + |
| 129 | +2. **Update OpenAPI Specification** |
| 130 | + - Explicitly mark optional fields as `nullable: true` in the YAML spec |
| 131 | + - Location: `sendbird-platform-openapi/sendbird.yaml` |
| 132 | + |
| 133 | +3. **Post-Processing Script** |
| 134 | + - Create a script to automatically add `none_type` to optional fields after generation |
| 135 | + - Similar to existing `post_process_nullable_fields_auto.py` |
| 136 | + |
| 137 | +### Recommendation |
| 138 | + |
| 139 | +Update the OpenAPI specification or generator configuration to properly handle optional fields: |
| 140 | + |
| 141 | +```yaml |
| 142 | +# In sendbird.yaml |
| 143 | +properties: |
| 144 | + discovery_keys: |
| 145 | + type: array |
| 146 | + items: |
| 147 | + type: string |
| 148 | + nullable: true # Add this for optional fields |
| 149 | +``` |
| 150 | +
|
| 151 | +### References |
| 152 | +
|
| 153 | +- OpenAPI Specification: [Nullable](https://swagger.io/docs/specification/data-models/data-types/#null) |
| 154 | +- Python OpenAPI Generator: [Issues with nullable](https://github.com/OpenAPITools/openapi-generator/issues?q=nullable+python) |
| 155 | +- Related test files: |
| 156 | + - `test/test_accept_an_invitation_request.py` |
| 157 | + - `test/test_create_a_user_request.py` |
| 158 | + - `test/test_sendbird_user.py` |
| 159 | + |
| 160 | +--- |
| 161 | + |
| 162 | +**Last Updated**: 2025-10-16 |
| 163 | +**Reported By**: Automated Test Suite |
| 164 | +**Priority**: Medium - Affects developer experience but has workarounds |
| 165 | + |
0 commit comments