-
Notifications
You must be signed in to change notification settings - Fork 155
Description
Current Behavior
When the Twitter profile retrieval endpoint returns a response containing explicit null values (e.g., {"name": null, "desc": null}), the backend crashes during Pydantic model validation. The current implementation uses Python's .get("field", "default") pattern, which only provides default values for missing keys, not for keys with null values. When a key exists but has a null value, that null is passed directly to the Pydantic model, causing a validation error and crashing the service.
Reproduction Steps:
- Make the backend automatically return null values when calling the Twitter retrieval endpoint
- Observe: The backend crashes with a Pydantic validation error when trying to process the response
- Check the logs to see the validation failure on fields that received
nullinstead of expected string/integer types
Expected Behavior
The backend should gracefully handle Twitter API responses containing null values without crashing. When a field contains null, the system should treat it the same as a missing field and apply appropriate default values (empty strings for text fields, 0 for numeric fields). The frontend should receive a properly formatted response, potentially with a status indicator like "suspended" or "notfound" to inform the user about the account state.
Acceptance Criteria:
- Backend processes Twitter API responses with
nullvalues without crashing - Fields with
nullvalues are converted to appropriate defaults (empty strings for text, 0 for numbers) - The TwitterProfile model successfully validates even when the API returns
nullvalues - Frontend displays appropriate error messages for suspended or not-found Twitter accounts
- Existing functionality for valid Twitter profiles remains unchanged
Steps To Test
For this task, you do NOT have to set up Twitter API credentials. Simply showing the backend can handle null values is alright.
- Configure the backend to return null values when calling the Twitter endpoint
- Verify the backend returns a response without crashing
- Check that the response contains appropriate default values instead of
null - Verify the frontend displays an appropriate error message (e.g., "Twitter handle is suspended")
Submission
Download https://cap.so/ to record your screen (use Studio mode). Export as an mp4, and drag and drop into an issue comment below.
Guide to submitting pull requests: https://hackmd.io/@timothy1ee/Hky8kV3hlx