Skip to content

Issue #16 - [BUG] Backend crashes when Twitter API returns null values in profile data #25

@rogelio-cmj

Description

@rogelio-cmj

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:

  1. Make the backend automatically return null values when calling the Twitter retrieval endpoint
  2. Observe: The backend crashes with a Pydantic validation error when trying to process the response
  3. Check the logs to see the validation failure on fields that received null instead 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 null values without crashing
  • Fields with null values are converted to appropriate defaults (empty strings for text, 0 for numbers)
  • The TwitterProfile model successfully validates even when the API returns null values
  • 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.

  1. Configure the backend to return null values when calling the Twitter endpoint
  2. Verify the backend returns a response without crashing
  3. Check that the response contains appropriate default values instead of null
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions